-
Notifications
You must be signed in to change notification settings - Fork 240
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
sliding sync: infer the storage key from the loop id and user id #2008
Conversation
Signed-off-by: Benjamin Bouvier <public@benj.me>
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.
First, I would not name this loop_id
but maybe just sync_id
. The user of SlidingSync
doesn't need to know about “loop” and it can be really confusing for a first discovering of the API.
Second, I don't see the point of this. I take on me the fact I'm probably tired and that I don't understand your long-term plan, but why is it needed to specify the “storage key” directly in the SS constructor?
use tracing::{trace, warn}; | ||
|
||
use super::{FrozenSlidingSync, FrozenSlidingSyncList, SlidingSync, SlidingSyncList}; | ||
use crate::{sliding_sync::SlidingSyncListCachePolicy, Client, Result}; | ||
|
||
pub(super) fn format_base_storage_key_for_sliding_sync(loop_id: &str, user_id: &UserId) -> String { | ||
format!("{}::{}", loop_id, user_id.to_string()) |
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 would prefix with matrix_sdk::sliding_sync::
or something like that to avoid possible naming conflicts.
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.
Done; I've also rejiggered how the other keys were computed. As a note: that means we're changing them, and this will invalidate the cache for all the current users.
That makes sense!
Oh the goal is two-fold here, I am feeding two birds with one seed:
Does it make more sense? |
Signed-off-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Benjamin Bouvier <public@benj.me>
Now the prefix is visible only in the `format_storage_key_prefix` function, and other `format_storage_key` function will be based off that. Signed-off-by: Benjamin Bouvier <public@benj.me>
…nformation Signed-off-by: Benjamin Bouvier <public@benj.me>
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.
It looks good to me, great job!
Is it possible to enable the caching if cached_list
is called? Thoughts?
@@ -414,6 +419,7 @@ impl SlidingSync { | |||
( | |||
// Build the request itself. | |||
assign!(v4::Request::new(), { | |||
// conn_id: self.inner.loop_id.clone(), |
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.
Is it a todo?
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.
As you remind me, the MSC says that the conn_id
must have a max length of 16.
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, a todo that will make sense when we have the dual sync loop split. I've also taken care of validating the identifier in a new version of this PR.
@@ -7,8 +7,8 @@ use crate::{Client, Result}; | |||
|
|||
impl Client { | |||
/// Create a [`SlidingSyncBuilder`] tied to this client. | |||
pub fn sliding_sync(&self) -> SlidingSyncBuilder { | |||
SlidingSync::builder(self.clone()) | |||
pub fn sliding_sync(&self, loop_id: impl Into<String>) -> SlidingSyncBuilder { |
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.
pub fn sliding_sync(&self, loop_id: impl Into<String>) -> SlidingSyncBuilder { | |
pub fn sliding_sync<I>(&self, loop_id: I) -> SlidingSyncBuilder where I: Into<String>{ |
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'm happy to do the change, is there a list of recommended idioms? (I kind of prefer the impl
in argument position, as it's slightly faster to type, but I get that it may hide the fact that this function's generic.)
I've given it a bit more thought, and I think we shouldn't: |
Signed-off-by: Benjamin Bouvier <public@benj.me>
bye bye clean commit history Signed-off-by: Benjamin Bouvier <public@benj.me>
Codecov ReportPatch and project coverage have no change.
Additional details and impacted files@@ Coverage Diff @@
## main #2008 +/- ##
=======================================
Coverage 74.72% 74.72%
=======================================
Files 138 138
Lines 14952 14952
=======================================
Hits 11173 11173
Misses 3779 3779
☔ View full report in Codecov by Sentry. |
This replaces the
storage_key
public API with another oneenable_caching
that doesn't take a string argument. Instead, sliding sync constructors are expected to receive aloop_id
argument, that will be used to 1. be part of the storage key for this sliding sync instance, 2. be used as theconn_id
(connection id) in the request to the proxy (paving the way for #1928).The storage key is also inferred from the user id, such that a single app may be used for multiple users.
Fixes #2007.