Skip to content

Commit

Permalink
Sliding Sync: Parameterize and add more tests for tracking changes to…
Browse files Browse the repository at this point in the history
… required state (#17805)

Parameterize and add more tests for tracking changes to required state
(`_required_state_changes(...)`)

These are direct modifications to
#17785 and should be merged
into that PR.
  • Loading branch information
MadLittleMods authored Oct 9, 2024
1 parent 5e66e98 commit 596581a
Show file tree
Hide file tree
Showing 3 changed files with 604 additions and 356 deletions.
1 change: 1 addition & 0 deletions changelog.d/17805.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug with sliding sync where the server would not return state that was added to the `required_state` config.
24 changes: 18 additions & 6 deletions synapse/handlers/sliding_sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,13 @@ def _required_state_changes(
prev_wildcard = prev_required_state_map.get(StateValues.WILDCARD, set())
request_wildcard = request_required_state_map.get(StateValues.WILDCARD, set())

# If we were previously fetching everything ("*", "*"), always update the effective
# room required state config to match the request. And since we we're previously
# already fetching everything, we don't have to fetch anything now that they've
# narrowed.
if StateValues.WILDCARD in prev_wildcard:
return request_required_state_map, StateFilter.none()

# If a event type wildcard has been added or removed we don't try and do
# anything fancy, and instead always update the effective room required
# state config to match the request.
Expand Down Expand Up @@ -1349,6 +1356,11 @@ def _required_state_changes(
# Always update changes to include the newly added keys
changes[event_type] = request_state_keys

if StateValues.WILDCARD in old_state_keys:
# We were previously fetching everything for this type, so we don't need to
# fetch anything new.
continue

# Record the new state keys to fetch for this type.
if StateValues.WILDCARD in request_state_keys:
# If we have added a wildcard then we always just fetch everything.
Expand All @@ -1358,8 +1370,8 @@ def _required_state_changes(
if state_key == StateValues.ME:
added.append((event_type, user_id))
elif state_key == StateValues.LAZY:
# We handle lazy loading separately, so don't need to
# explicitly add anything here.
# We handle lazy loading separately (outside this function), so
# don't need to explicitly add anything here.
pass
else:
added.append((event_type, state_key))
Expand Down Expand Up @@ -1397,17 +1409,17 @@ def _required_state_changes(
request_state_key_wildcard = StateValues.WILDCARD in request_state_keys

if old_state_key_wildcard != request_state_key_wildcard:
# If a wildcard has been added or removed we always update the
# required state when any state with the same type has changed.
# If a state_key wildcard has been added or removed, we always update the
# effective room required state config to match the request.
changes[event_type] = request_state_keys
continue

old_state_key_lazy = StateValues.LAZY in old_state_keys
request_state_key_lazy = StateValues.LAZY in request_state_keys

if old_state_key_lazy != request_state_key_lazy:
# If a "$LAZY" has been added or removed we always update the
# required state for simplicity.
# If a "$LAZY" has been added or removed we always update the effective room
# required state config to match the request.
changes[event_type] = request_state_keys
continue

Expand Down
Loading

0 comments on commit 596581a

Please sign in to comment.