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

Expose subscriptions more directly #6231

Merged
merged 23 commits into from
Oct 26, 2018
Merged

Expose subscriptions more directly #6231

merged 23 commits into from
Oct 26, 2018

Conversation

cmelchior
Copy link
Contributor

@cmelchior cmelchior commented Oct 12, 2018

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.

  • Added new Subscription model class that represents __ResultSets objects.
  • Added Realm.getSubscriptions(), Realm.getSubscriptions(String pattern), Realm.getSubscription(String name).
    • Added RealmQuery.subscribe() that creates the subscription directly (requires a write transaction).
  • If SyncConfiguration.waitForInitialRemoteData() is set and SyncConfiguration.initialData() creates subscriptions, the Realm isn't opened until the subscriptions have downloaded data.

TODO:

@cmelchior
Copy link
Contributor Author

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)

Copy link
Member

@kneth kneth left a 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)

CHANGELOG.md Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
realm/realm-library/src/main/java/io/realm/RealmCache.java Outdated Show resolved Hide resolved
realm/realm-library/src/main/java/io/realm/RealmCache.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()},
Copy link
Member

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"

* @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) {
Copy link
Collaborator

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

Copy link
Contributor Author

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
Copy link
Collaborator

@nhachicha nhachicha Oct 22, 2018

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/RealmQuery.java Outdated Show resolved Hide resolved
Copy link
Collaborator

@nhachicha nhachicha left a 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

@bmunkholm bmunkholm requested a review from tgoyne October 24, 2018 10:05
@tgoyne
Copy link
Member

tgoyne commented Oct 24, 2018

Maybe the query API is sufficiently different to begin with that it isn't a big deal, but it's potentially confusing to add .subscribe() and .unsubscribe() methods with different semantics from what the the methods with those names do in all of the other SDKs.

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
Copy link
Contributor

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?

@bmunkholm
Copy link
Contributor

Regarding the comment from Thomas:

Maybe the query API is sufficiently different to begin with that it isn't a big deal, but it's potentially confusing to add .subscribe() and .unsubscribe() methods with different semantics from what the methods with those names do in all of the other SDKs.

I think it's a problem if we make naming the same but semantics different. We should avoid that if at all possible.

@cmelchior
Copy link
Contributor Author

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 subscribe() encapsulates the meaning of actually creating the subscription on both platforms, so even though the semantics are different, the end result is more or less the same.

@cmelchior cmelchior merged commit 1c71cac into master Oct 26, 2018
@cmelchior cmelchior deleted the cm/better-subscriptions branch October 26, 2018 17:14
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants