Uploaded image for project: 'Realm Kotlin'
  1. Realm Kotlin
  2. RKOTLIN-988

Batch data updates are slow

      How frequently does the bug occur?

      Always

      Description

      The version of realm I'm currently using is io.realm.kotlin:library-base:1.8.0, which can be tricky when I want to update the local list data to the status field. Here is my code and test results

      realm.writeBlocking {
                  val status = msgChat.status
                  val result = query(MsgChatRealm::class, "cvsId == '${msgChat.cvsId}'")
                      .query("from != '${IM.api()?.getUserId()}'")
                      .query("status == ANY{${needUpdateStatusArray.joinToString()}}")
                      .query("timestamp <= '${oldTimestamp}'")
                      .find()//.map { it.toEntity() }.toMutableList()
                  Log.d("updateOppositeStatusByMaxTimeMsgChat=>", "size : ${result.size}")
                  for (qr in result) {
                      findLatest(qr)?.status = status
                  }
                  Log.d(
                      "updateOppositeStatusByMaxTimeMsgChat=>",
                      "dif : ${System.currentTimeMillis() - time}"
                  )
              }
      16:46:17.210 13531-13892 updateOppos...meMsgChat=>  D  start : 1703580377210
      16:46:17.264 13531-13899 updateOppos...meMsgChat=>  D  start : 1703580377264
      16:46:17.356 13531-13903 updateOppos...meMsgChat=>  D  start : 1703580377356
      16:46:17.465 13531-13905 updateOppos...meMsgChat=>  D  start : 1703580377465
      16:46:20.193 13531-13593 updateOppos...meMsgChat=>  D  dif : 5178
      16:46:20.213 13531-13593 updateOppos...meMsgChat=>  D  size : 20
      16:46:20.325 13531-13593 updateOppos...meMsgChat=>  D  dif : 5310
      16:46:20.344 13531-13593 updateOppos...meMsgChat=>  D  size : 9
      16:46:20.410 13531-13593 updateOppos...meMsgChat=>  D  dif : 5394
      16:46:20.430 13531-13593 updateOppos...meMsgChat=>  D  size : 3
      16:46:20.474 13531-13593 updateOppos...meMsgChat=>  D  dif : 5456
      16:46:20.492 13531-13593 updateOppos...meMsgChat=>  D  size : 1
      16:46:20.526 13531-13593 updateOppos...meMsgChat=>  D  dif : 5508
      16:46:20.544 13531-13593 updateOppos...meMsgChat=>  D  size : 2
      16:46:20.585 13531-13593 updateOppos...meMsgChat=>  D  dif : 5564
      

      Database queries are fast, almost 1ms, but proceed

      for (qr in result) {
                      findLatest(qr)?.status = status
      }
      

      This operation will take more than 5s, is there any way to batch update data to improve performance

      Stacktrace & log output

      No response

      Can you reproduce the bug?

      Always

      Reproduction Steps

      No response

      Version

      1.8.0

      What Atlas App Services are you using?

      Local Database only

      Are you using encryption?

      Yes

      Platform OS and version(s)

      android 13

      Build environment

      Android Studio version: ...
      Android Build Tools version: ...
      Gradle version: ...

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: