-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Expose subscriptions more directly #6231
Conversation
Ready for review. The unit test failing is unrelated to the changes here(it is however pretty consistent, so I'll be looking into it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I have added a number of minor comments (mostly documentation)
realm/realm-library/src/main/java/io/realm/sync/Subscription.java
Outdated
Show resolved
Hide resolved
realm/realm-library/src/main/java/io/realm/sync/Subscription.java
Outdated
Show resolved
Hide resolved
* device. If an object is not covered by any subscription it will be removed from the device, | ||
* but not the server. | ||
* <p> | ||
* Subscriptions are Realm objects, so deleting them by e.g. calling {@link RealmObject#deleteFromRealm()}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"by e.g." -> "e.g. by"
realm/realm-library/src/objectServer/java/io/realm/internal/SyncObjectServerFacade.java
Outdated
Show resolved
Hide resolved
* @param realmFileExistedOnDisk {@code true} if the file existed on disk before trying to open the Realm. | ||
*/ | ||
private static void synchronizeInitialSubscriptionsIfNeeded(Realm realm, boolean realmFileExistedOnDisk) { | ||
if (!realmFileExistedOnDisk) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not do this check in https://github.com/realm/realm-java/pull/6231/files#diff-79e6ca3beee0a83dd76772285b606694R351 realmFileExistedOnDisk
is not needed in this function, maybe change the name to synchronizeInitialSubscriptions
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
realmFileExistedOnDisk
is set before creating anything at the entry of the function, but I agree the name isn't very descriptive at this point in time. I changed the name to realmFileIsBeingCreated
and reversed the boolean logic in the places required.
The check is here because initialData
is only ever called for typed Realms, not DynamicRealm.
@@ -340,6 +339,17 @@ private static RealmCache getCache(String realmPath, boolean createIfNotExist) { | |||
if (realmClass == Realm.class) { | |||
// RealmMigrationNeededException might be thrown here. | |||
realm = Realm.createInstance(this); | |||
|
|||
// If `waitForInitialRemoteData` data is set, we also want to ensure that all subscriptions | |||
// are fully ready before proceeding. The `initialData` block is only executed for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can be there any subscription(s) before opening the Realm? Ok via initialData
realm/realm-library/src/main/java/io/realm/sync/Subscription.java
Outdated
Show resolved
Hide resolved
realm/realm-library/src/objectServer/java/io/realm/internal/SyncObjectServerFacade.java
Outdated
Show resolved
Hide resolved
realm/realm-library/src/objectServer/java/io/realm/internal/SyncObjectServerFacade.java
Show resolved
Hide resolved
realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/QueryBasedSyncTests.java
Show resolved
Hide resolved
realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/QueryBasedSyncTests.java
Show resolved
Hide resolved
# Conflicts: # CHANGELOG.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR, this should solve a bunch of issues with the subscription/initial state. 👍 if CI is happy
Maybe the query API is sufficiently different to begin with that it isn't a big deal, but it's potentially confusing to add Nothing else really stands out to me. |
@@ -29,7 +49,7 @@ | |||
* APIs are backwards compatible with all previous release of realm-java in the 5.x.y series. | |||
|
|||
### Internal | |||
* None | |||
* Updated to Object Store commit: 362b886628b3aefc5b7a0bc32293d794dc1d4ad5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that solve any issues in Java?
Regarding the comment from Thomas:
I think it's a problem if we make naming the same but semantics different. We should avoid that if at all possible. |
Yes, we should. But in this case, it isn't possible. It is virtually impossible to make these API's similar as the way queries are performed and run are so very different between Java and Cocoa/JS and changing that would be a massive, massive change for all existing users. The name |
… starting the next one.
3114cd3
to
dc1ff5b
Compare
Expose Subscriptions more directly, so it is easier to create, find and remove them. This mirrors the API's in realm/realm-js#2060 but exposes the Subscription class more directly as it makes it easier to query, list and manipulate the subscriptions.
Subscription
model class that represents__ResultSets
objects.Realm.getSubscriptions()
,Realm.getSubscriptions(String pattern)
,Realm.getSubscription(String name)
.• Added
RealmQuery.subscribe()
that creates the subscription directly (requires a write transaction).SyncConfiguration.waitForInitialRemoteData()
is set andSyncConfiguration.initialData()
creates subscriptions, the Realm isn't opened until the subscriptions have downloaded data.TODO: