Uploaded image for project: 'Realm Java SDK'
  1. Realm Java SDK
  2. RJAVA-550

Consider letting SyncSession.downloadAllServerChanges() also refresh the Realm

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      Consider the following test code:

              val realm = Realm.getInstance(config2)
              realm.syncSession.downloadAllServerChanges()
              // realm.refresh() Required for below code to work
              assertEquals(10, realm.where<SyncDog>().count())
              assertEquals(1, realm.where<SyncPerson>().count())
      

      By reading it you would assume it would work, but it doesn't. The reason is that downloadAllServerChanges run on the Sync Client worker thread and when it completes the caller thread has not been updated yet.

      Instead, you manually need to add a realm.refresh() after calling download().

      We should consider doing that automatically. Realms normally using this API are not looper threads, so we don't need to be particularly worried about callbacks.

      The only annoying thing is that the Session and Realm are largely uncoupled. The session is e.g. not thread confined, while the Realm is. So we need a clever way of finding any open Realms on the current thread, and there might be multiple (think typed and Dynamic Realm).

      But maybe this is just too confusing...something to ponder.

            Assignee:
            Unassigned Unassigned
            Reporter:
            christian.melchior@mongodb.com Christian Melchior (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: