Skip to content

Commit 596581a

Browse files
Sliding Sync: Parameterize and add more tests for tracking changes to 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.
1 parent 5e66e98 commit 596581a

File tree

3 files changed

+604
-356
lines changed

3 files changed

+604
-356
lines changed

changelog.d/17805.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug with sliding sync where the server would not return state that was added to the `required_state` config.

synapse/handlers/sliding_sync/__init__.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,13 @@ def _required_state_changes(
13131313
prev_wildcard = prev_required_state_map.get(StateValues.WILDCARD, set())
13141314
request_wildcard = request_required_state_map.get(StateValues.WILDCARD, set())
13151315

1316+
# If we were previously fetching everything ("*", "*"), always update the effective
1317+
# room required state config to match the request. And since we we're previously
1318+
# already fetching everything, we don't have to fetch anything now that they've
1319+
# narrowed.
1320+
if StateValues.WILDCARD in prev_wildcard:
1321+
return request_required_state_map, StateFilter.none()
1322+
13161323
# If a event type wildcard has been added or removed we don't try and do
13171324
# anything fancy, and instead always update the effective room required
13181325
# state config to match the request.
@@ -1349,6 +1356,11 @@ def _required_state_changes(
13491356
# Always update changes to include the newly added keys
13501357
changes[event_type] = request_state_keys
13511358

1359+
if StateValues.WILDCARD in old_state_keys:
1360+
# We were previously fetching everything for this type, so we don't need to
1361+
# fetch anything new.
1362+
continue
1363+
13521364
# Record the new state keys to fetch for this type.
13531365
if StateValues.WILDCARD in request_state_keys:
13541366
# If we have added a wildcard then we always just fetch everything.
@@ -1358,8 +1370,8 @@ def _required_state_changes(
13581370
if state_key == StateValues.ME:
13591371
added.append((event_type, user_id))
13601372
elif state_key == StateValues.LAZY:
1361-
# We handle lazy loading separately, so don't need to
1362-
# explicitly add anything here.
1373+
# We handle lazy loading separately (outside this function), so
1374+
# don't need to explicitly add anything here.
13631375
pass
13641376
else:
13651377
added.append((event_type, state_key))
@@ -1397,17 +1409,17 @@ def _required_state_changes(
13971409
request_state_key_wildcard = StateValues.WILDCARD in request_state_keys
13981410

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

14051417
old_state_key_lazy = StateValues.LAZY in old_state_keys
14061418
request_state_key_lazy = StateValues.LAZY in request_state_keys
14071419

14081420
if old_state_key_lazy != request_state_key_lazy:
1409-
# If a "$LAZY" has been added or removed we always update the
1410-
# required state for simplicity.
1421+
# If a "$LAZY" has been added or removed we always update the effective room
1422+
# required state config to match the request.
14111423
changes[event_type] = request_state_keys
14121424
continue
14131425

0 commit comments

Comments
 (0)