Skip to content

Commit 1192a4b

Browse files
committed
Rename previously_returned_user_state param
1 parent 2090d14 commit 1192a4b

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

synapse/handlers/sliding_sync/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,23 +1216,23 @@ async def get_room_sync_data(
12161216
# the case where the client added explicit user state requests
12171217
# for users they already had lazy loaded.
12181218
if all_required_user_state:
1219-
previously_returned_user_state = (
1219+
previously_returned_user_to_last_seen = (
12201220
await self.store.get_sliding_sync_connection_lazy_members(
12211221
connection_position=from_token.connection_position,
12221222
room_id=room_id,
12231223
user_ids=all_required_user_state,
12241224
)
12251225
)
12261226
else:
1227-
previously_returned_user_state = {}
1227+
previously_returned_user_to_last_seen = {}
12281228

12291229
# Check if there are any changes to the required state config
12301230
# that we need to handle.
12311231
changes_return = _required_state_changes(
12321232
user.to_string(),
12331233
prev_required_state_map=prev_room_sync_config.required_state_map,
12341234
request_required_state_map=room_sync_config.required_state_map,
1235-
previously_returned_user_state=previously_returned_user_state,
1235+
previously_returned_user_ids=previously_returned_user_to_last_seen.keys(),
12361236
lazy_load_user_ids=lazy_load_user_ids,
12371237
state_deltas=room_state_delta_id_map,
12381238
)
@@ -1570,7 +1570,7 @@ def _required_state_changes(
15701570
*,
15711571
prev_required_state_map: Mapping[str, AbstractSet[str]],
15721572
request_required_state_map: Mapping[str, AbstractSet[str]],
1573-
previously_returned_user_state: Mapping[str, int | None],
1573+
previously_returned_user_ids: AbstractSet[str],
15741574
lazy_load_user_ids: AbstractSet[str],
15751575
state_deltas: StateMap[str],
15761576
) -> _RequiredStateChangesReturn:
@@ -1593,9 +1593,11 @@ def _required_state_changes(
15931593
request.
15941594
request_required_state_map: The required state map from the current
15951595
request.
1596-
previously_returned_user_state: The set of user IDs whose lazy-loaded
1597-
membership we have previously returned to the client.
1598-
required_user_state: The set of user IDs whose lazy-loaded membership
1596+
previously_returned_user_state: The set of user IDs whose membership
1597+
we have previously returned to the client. This is filtered to
1598+
only include users who have either sent events in the timeline
1599+
or required state.
1600+
lazy_load_user_ids: The set of user IDs whose lazy-loaded membership
15991601
is required for this request.
16001602
state_deltas: The state deltas that have changed in the room since the
16011603
previous request.
@@ -1613,7 +1615,7 @@ def _required_state_changes(
16131615
# send this member change down.
16141616
continue
16151617

1616-
if state_key not in previously_returned_user_state:
1618+
if state_key not in previously_returned_user_ids:
16171619
# We've not previously returned this member so nothing to
16181620
# invalidate.
16191621
continue
@@ -1622,9 +1624,7 @@ def _required_state_changes(
16221624

16231625
if prev_required_state_map == request_required_state_map:
16241626
# There has been no change in state, just need to check lazy members.
1625-
newly_returned_lazy_members = (
1626-
lazy_load_user_ids - previously_returned_user_state.keys()
1627-
)
1627+
newly_returned_lazy_members = lazy_load_user_ids - previously_returned_user_ids
16281628
if newly_returned_lazy_members:
16291629
# There are some new lazy members we need to fetch.
16301630
added_types: list[tuple[str, str | None]] = []
@@ -1812,7 +1812,7 @@ def _required_state_changes(
18121812
# not membership.
18131813
pass
18141814
elif event_type == EventTypes.Member:
1815-
if state_key not in previously_returned_user_state:
1815+
if state_key not in previously_returned_user_ids:
18161816
# Only add *explicit* members we haven't previously sent
18171817
# down.
18181818
added.append((event_type, state_key))
@@ -1823,7 +1823,7 @@ def _required_state_changes(
18231823
# haven't previously been returned.
18241824
for required_user_id in (
18251825
lazy_load_user_ids
1826-
- previously_returned_user_state.keys()
1826+
- previously_returned_user_ids
18271827
- lazy_members_previously_returned
18281828
):
18291829
added.append((EventTypes.Member, required_user_id))

tests/handlers/test_sliding_sync.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,7 +3834,7 @@ class RequiredStateChangesTestParameters:
38343834
expected_with_state_deltas: _RequiredStateChangesReturn
38353835
expected_without_state_deltas: _RequiredStateChangesReturn
38363836

3837-
previously_returned_user_state: AbstractSet[str] = frozenset()
3837+
previously_returned_user_ids: AbstractSet[str] = frozenset()
38383838
lazy_load_user_ids: AbstractSet[str] = frozenset()
38393839

38403840

@@ -4370,7 +4370,7 @@ class RequiredStateChangesTestCase(unittest.TestCase):
43704370
RequiredStateChangesTestParameters(
43714371
previous_required_state_map={EventTypes.Member: {StateValues.LAZY}},
43724372
request_required_state_map={EventTypes.Member: {StateValues.LAZY}},
4373-
previously_returned_user_state={"@user2:test", "@user3:test"},
4373+
previously_returned_user_ids={"@user2:test", "@user3:test"},
43744374
lazy_load_user_ids=set(),
43754375
state_deltas={(EventTypes.Member, "@user2:test"): "$event_id"},
43764376
expected_with_state_deltas=_RequiredStateChangesReturn(
@@ -4415,7 +4415,7 @@ class RequiredStateChangesTestCase(unittest.TestCase):
44154415
RequiredStateChangesTestParameters(
44164416
previous_required_state_map={EventTypes.Member: {StateValues.LAZY}},
44174417
request_required_state_map={EventTypes.Member: {StateValues.LAZY}},
4418-
previously_returned_user_state={"@user2:test", "@user3:test"},
4418+
previously_returned_user_ids={"@user2:test", "@user3:test"},
44194419
lazy_load_user_ids={"@user4:test"},
44204420
state_deltas={(EventTypes.Member, "@user2:test"): "$event_id"},
44214421
expected_with_state_deltas=_RequiredStateChangesReturn(
@@ -4457,7 +4457,7 @@ class RequiredStateChangesTestCase(unittest.TestCase):
44574457
EventTypes.Member: {"@user2:test", "@user3:test"}
44584458
},
44594459
request_required_state_map={EventTypes.Member: {StateValues.LAZY}},
4460-
previously_returned_user_state=frozenset(),
4460+
previously_returned_user_ids=frozenset(),
44614461
lazy_load_user_ids={"@user3:test"},
44624462
state_deltas={(EventTypes.Member, "@user2:test"): "$event_id"},
44634463
expected_with_state_deltas=_RequiredStateChangesReturn(
@@ -4501,7 +4501,7 @@ class RequiredStateChangesTestCase(unittest.TestCase):
45014501
RequiredStateChangesTestParameters(
45024502
previous_required_state_map={EventTypes.Member: {StateValues.LAZY}},
45034503
request_required_state_map={},
4504-
previously_returned_user_state={"@user2:test", "@user3:test"},
4504+
previously_returned_user_ids={"@user2:test", "@user3:test"},
45054505
lazy_load_user_ids=set(),
45064506
state_deltas={(EventTypes.Member, "@user2:test"): "$event_id"},
45074507
expected_with_state_deltas=_RequiredStateChangesReturn(
@@ -4549,7 +4549,7 @@ class RequiredStateChangesTestCase(unittest.TestCase):
45494549
RequiredStateChangesTestParameters(
45504550
previous_required_state_map={EventTypes.Member: {StateValues.LAZY}},
45514551
request_required_state_map={EventTypes.Member: {"@user4:test"}},
4552-
previously_returned_user_state={"@user2:test", "@user3:test"},
4552+
previously_returned_user_ids={"@user2:test", "@user3:test"},
45534553
lazy_load_user_ids={"@user4:test"},
45544554
state_deltas={(EventTypes.Member, "@user2:test"): "$event_id"},
45554555
expected_with_state_deltas=_RequiredStateChangesReturn(
@@ -4720,19 +4720,12 @@ def test_xxx(
47204720
_test_description: str,
47214721
test_parameters: RequiredStateChangesTestParameters,
47224722
) -> None:
4723-
# `_required_state_changes` expects this to be a map from user ID to
4724-
# timestamp, so let's convert it into one by using a dummy timestamp
4725-
# value
4726-
previously_returned_user_state = dict.fromkeys(
4727-
test_parameters.previously_returned_user_state, 1234
4728-
)
4729-
47304723
# Without `state_deltas`
47314724
state_changes = _required_state_changes(
47324725
user_id="@user:test",
47334726
prev_required_state_map=test_parameters.previous_required_state_map,
47344727
request_required_state_map=test_parameters.request_required_state_map,
4735-
previously_returned_user_state=previously_returned_user_state,
4728+
previously_returned_user_ids=test_parameters.previously_returned_user_ids,
47364729
lazy_load_user_ids=test_parameters.lazy_load_user_ids,
47374730
state_deltas={},
47384731
)
@@ -4763,7 +4756,7 @@ def test_xxx(
47634756
user_id="@user:test",
47644757
prev_required_state_map=test_parameters.previous_required_state_map,
47654758
request_required_state_map=test_parameters.request_required_state_map,
4766-
previously_returned_user_state=previously_returned_user_state,
4759+
previously_returned_user_ids=test_parameters.previously_returned_user_ids,
47674760
lazy_load_user_ids=test_parameters.lazy_load_user_ids,
47684761
state_deltas=test_parameters.state_deltas,
47694762
)
@@ -4827,7 +4820,7 @@ def test_limit_retained_previous_state_keys(
48274820
user_id="@user:test",
48284821
prev_required_state_map=previous_required_state_map,
48294822
request_required_state_map=request_required_state_map,
4830-
previously_returned_user_state={},
4823+
previously_returned_user_ids=frozenset(),
48314824
lazy_load_user_ids=frozenset(),
48324825
state_deltas={},
48334826
)
@@ -4900,7 +4893,7 @@ def test_request_more_state_keys_than_remember_limit(self) -> None:
49004893
user_id="@user:test",
49014894
prev_required_state_map=previous_required_state_map,
49024895
request_required_state_map=request_required_state_map,
4903-
previously_returned_user_state={},
4896+
previously_returned_user_ids=frozenset(),
49044897
lazy_load_user_ids=frozenset(),
49054898
state_deltas={},
49064899
)

0 commit comments

Comments
 (0)