-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Ensure realm subscriptions always fire initial callback with null ChangeSet
#28785
Conversation
…angeSet` We expect this to be the case, but it turns out that it [may be coalesced](https://www.mongodb.com/docs/realm-sdks/dotnet/latest/reference/Realms.IRealmCollection-1.html#Realms_IRealmCollection_1_SubscribeForNotifications_Realms_NotificationCallbackDelegate__0__Realms_KeyPathsCollection_): > Notifications are delivered via the standard event loop, and so can't > be delivered while the event loop is blocked by other activity. When > notifications can't be delivered instantly, multiple notifications may > be coalesced into a single notification. This can include the > notification with the initial collection. Rather than struggle with handling this locally every time, let's fix the callback at our end to ensure we receive the initial null case. I've raised concern for the API being a bit silly with realm (realm/realm-dotnet#3641).
Hold up this isn't correct. |
if (changes != null) | ||
callback(sender, null); | ||
} | ||
|
||
callback(sender, changes); |
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.
If sender
contains the items after the modifications are applied, then shouldn't we not send the non-null callback if initial == true
?
To further expound, when you send (sender, null)
, the callsite will use those items to populate the initial list:
osu/osu.Game/Screens/Select/BeatmapCarousel.cs
Lines 279 to 282 in c100d1a
if (changes == null) | |
{ | |
realmBeatmapSets.Clear(); | |
realmBeatmapSets.AddRange(sender.Select(r => r.ID)); |
But then we send the (sender, changes)
callback which could be used to e.g. delete from that "initial list" from above:
osu/osu.Game/Screens/Select/BeatmapCarousel.cs
Lines 290 to 294 in c100d1a
foreach (int i in changes.DeletedIndices.OrderDescending()) | |
{ | |
setsRequiringRemoval.Add(realmBeatmapSets[i]); | |
realmBeatmapSets.RemoveAt(i); | |
} |
But the deleted indices are actually irrelevant here because we did not previously have an initial list.
It depends on what sender
truly is in the case when the changes have been coalesced - is it the initial list before any modifications, or is it the list after all coalesced modifications.
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.
Yeah just noticed this very thing in further testing. Fixed in ee9e329.
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.
Makes sense to me
We expect this to be the case, but it turns out that it may be coalesced:
Rather than struggle with handling this locally every time, let's fix the callback at our end to ensure we receive the initial null case.
I've raised concern for the API being a bit silly with realm (realm/realm-dotnet#3641).