Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider letting SyncSession.downloadAllServerChanges() also refresh the Realm #6814

Open
cmelchior opened this issue Apr 27, 2020 · 0 comments

Comments

@cmelchior
Copy link
Contributor

cmelchior commented Apr 27, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant