-
Notifications
You must be signed in to change notification settings - Fork 262
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
feat: add add_cached_list
to SlidingSyncBuilder
and SlidingSync
#1876
Conversation
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
…Builder::add_cached_list` Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
cc @stefanceriu, in case you want to test it, have feedback on the API, etc. :) |
Codecov ReportPatch and project coverage have no change.
Additional details and impacted files@@ Coverage Diff @@
## main #1876 +/- ##
=======================================
Coverage 76.27% 76.27%
=======================================
Files 141 141
Lines 16089 16089
=======================================
Hits 12272 12272
Misses 3817 3817
☔ View full report in Codecov by Sentry. |
|
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.
Looks good to me so far. The design is nice and is definitely an improvement. Well done!
As I said, I would like to way on #1758 to be merged before merging this one as the behavior of add_list
changes.
|
||
/// Total number of rooms that is possible to interact with the given list. | ||
/// See also comment of [`SlidingSyncList::maximum_number_of_rooms`]. | ||
/// May be reloaded from the cache. |
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.
The only way to set those values are when it's reloaded from the cache. The doc' should emphasize that :-). It's not “may be reloaded from the cache” but rather “contains the default value, or the value from the cache, cannot be modified by the user”.
Question: Did we read those values from the cache previously?
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.
Yes, we did! That was the data that was merged in set_from_cold
, using observables (while in theory we should only have to use plain assignments, assuming reading from cache only happens at initialization).
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.
And good point; I've actually tweaked the data stored here, by introducing a new temporary data structure that contains only the cached data. That way, we can decide in build()
if we read the cached data or the default, and that puts the code assigning the defaults closer to the data read from the cache.
With #1758 now merged, should we rebase this and give it a shot? |
Yep, this one is next on my rebase list; I can let you Stefan know once this is ready? |
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
For what it's worth, modulo the doc issue, this is ready for review and testing. |
Will review 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.
Looks good to me!
@stefanceriu, can you test it before merging it please? Our tests are passing, but it's better testing than fixing.
Okay so I gave it a shot but I'm a bit confused by how this is supposed to work. If I do this: I get a
and if I do this: I get the same error
If I do this instead I don't get an error anymore but the list doesn't publish its total count anymore either. It's always zero even though it has rooms in it
I think we should get rid of the storage key entirely and only rely on the room name for the cache L.E. Interestingly enough the other 2 lists I add later do publish their room count
|
Thanks for testing! Indeed we should probably tweak the builders so the storage key has to be provided first, or the other method is not available until then (or have a sub-builder for caching that takes a storage key on creation). Right now the key for each list is composed of both the global storage key provided, as well as a suffix generated from the list's name. I assume that is so, in case the Rust SDK would be used in multiple apps (but in that case they would likely use different storage locations for the caches), or the same SDK used multiple times in the same app (less likely). Should we get rid of the storage key @Hywan? Regarding the other issue, I'll need to investigate a bit more. |
Signed-off-by: Benjamin Bouvier <[email protected]>
Co-authored-by: Jonas Platte <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
… in streams Signed-off-by: Benjamin Bouvier <[email protected]>
@stefanceriu confirmed (thanks!) that the latest commit fixes the issue about the initial value being not observed. I've added a test in #1922 that shows this behavior, and I can confirm it passes fine in this branch now (and didn't before the fix). |
Regarding the possibility to remove the |
So perhaps we should use the user's id as a key automagically? |
I don't think the |
ah good point, the sql stores are already stored in different folders based on the user id |
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.
LGTM :-)
Signed-off-by: Benjamin Bouvier <[email protected]>
887394a
to
ea6c962
Compare
Signed-off-by: Benjamin Bouvier <[email protected]>
This has slightly drifted from the initial design I thought about in the issue.
Instead of having
build()
be fallible and mutably borrow some substate (namelyBTreeMap<OwnedRoomId, SlidingSyncRoom>
) fromSlidingSync
(that may or may not already exist), I've introduced a newadd_cached_list
method onSlidingSync
andSlidingSyncBuilder
. This method hides all the underlying machinery, and injects the room data read from the list cache into the sliding sync room map.In particular, with these changes:
add_list
won't be loaded from/written to the cache storage,add_cached_list
will be cached, and an attempt to reload it from the cache will be done during this call (henceasync
+Result
).SlidingSyncBuilder::build()
now only fetches theSlidingSync
data from the cache (assuming the storage key has been defined), not that of the lists anymore.Also took the opportunity to rename
pop_list
toremove_list
, as there's no stack/vec involved thus popping sounded a bit weird to me.Fixes #1737.