-
Notifications
You must be signed in to change notification settings - Fork 538
Send a SSS response immediately if the config has changed and there are new results to sync #19714
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Have SSS return a new response immediately if a room subscription have changed and produced a new response. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,34 +167,38 @@ async def wait_for_sync_for_user( | |
| timeout_ms -= after_wait_ts - before_wait_ts | ||
| timeout_ms = max(timeout_ms, 0) | ||
|
|
||
| # We're going to respond immediately if the timeout is 0 or if this is an | ||
| # initial sync (without a `from_token`) so we can avoid calling | ||
| # `notifier.wait_for_events()`. | ||
| if timeout_ms == 0 or from_token is None: | ||
| now_token = self.event_sources.get_current_token() | ||
| result = await self.current_sync_for_user( | ||
| # Compute a response immediately. We always need to do this before | ||
| # waiting for new data (unlike in /v3/sync), as the request config might | ||
| # have changed (e.g. new room subscriptions, etc). | ||
| now_token = self.event_sources.get_current_token() | ||
| result = await self.current_sync_for_user( | ||
| sync_config, | ||
| from_token=from_token, | ||
| to_token=now_token, | ||
| ) | ||
|
|
||
| # Return immediately if we have a result, the timeout is 0, or this is | ||
| # an initial sync. | ||
| if result or timeout_ms == 0 or from_token is None: | ||
| return result, did_wait | ||
|
|
||
| # Otherwise, we wait for something to happen and report it to the user. | ||
| async def current_sync_callback( | ||
| before_token: StreamToken, after_token: StreamToken | ||
| ) -> SlidingSyncResult: | ||
| return await self.current_sync_for_user( | ||
| sync_config, | ||
| from_token=from_token, | ||
| to_token=now_token, | ||
| to_token=after_token, | ||
| ) | ||
| else: | ||
| # Otherwise, we wait for something to happen and report it to the user. | ||
| async def current_sync_callback( | ||
| before_token: StreamToken, after_token: StreamToken | ||
| ) -> SlidingSyncResult: | ||
| return await self.current_sync_for_user( | ||
| sync_config, | ||
| from_token=from_token, | ||
| to_token=after_token, | ||
| ) | ||
|
|
||
| result = await self.notifier.wait_for_events( | ||
| sync_config.user.to_string(), | ||
| timeout_ms, | ||
| current_sync_callback, | ||
| from_token=from_token.stream_token, | ||
| ) | ||
| did_wait = True | ||
| result = await self.notifier.wait_for_events( | ||
| sync_config.user.to_string(), | ||
| timeout_ms, | ||
| current_sync_callback, | ||
| from_token=now_token, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make sure I'm following this logic, we use Feels like this deserves a comment as an optimization. Something along the lines of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like #19734 is trying to address this |
||
| ) | ||
| did_wait = True | ||
|
|
||
| return result, did_wait | ||
|
|
||
|
|
||
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 PR description says this fixes #18844
But I don't see an associated test update as described in #18844 (comment)
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 like #19734 is trying to address this