Sliding sync: Ignore tables with no create event in current state (#17633)

This commit is contained in:
Erik Johnston 2024-08-30 08:54:14 +01:00 committed by GitHub
parent 7098d47f29
commit 89801e04ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 22 deletions

1
changelog.d/17633.misc Normal file
View file

@ -0,0 +1 @@
Pre-populate room data used in experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync` endpoint for quick filtering/sorting.

View file

@ -2080,9 +2080,10 @@ class EventsBackgroundUpdatesStore(StreamWorkerStore, StateDeltasStore, SQLBaseS
# We're iterating over rooms that we are joined to so they should # We're iterating over rooms that we are joined to so they should
# have `current_state_events` and we should have some current state # have `current_state_events` and we should have some current state
# for each room # for each room
assert current_state_ids_map if current_state_ids_map:
fetched_events = await self.get_events(
fetched_events = await self.get_events(current_state_ids_map.values()) current_state_ids_map.values()
)
current_state_map: StateMap[EventBase] = { current_state_map: StateMap[EventBase] = {
state_key: fetched_events[event_id] state_key: fetched_events[event_id]
@ -2097,17 +2098,31 @@ class EventsBackgroundUpdatesStore(StreamWorkerStore, StateDeltasStore, SQLBaseS
if not current_state_map: if not current_state_map:
continue continue
state_insert_values = ( state_insert_values = PersistEventsStore._get_sliding_sync_insert_values_from_state_map(
PersistEventsStore._get_sliding_sync_insert_values_from_state_map(
current_state_map current_state_map
) )
sliding_sync_membership_snapshots_insert_map.update(
state_insert_values
) )
sliding_sync_membership_snapshots_insert_map.update(state_insert_values)
# We should have some insert values for each room, even if they are `None` # We should have some insert values for each room, even if they are `None`
assert sliding_sync_membership_snapshots_insert_map assert sliding_sync_membership_snapshots_insert_map
# We have current state to work from # We have current state to work from
sliding_sync_membership_snapshots_insert_map["has_known_state"] = True sliding_sync_membership_snapshots_insert_map["has_known_state"] = (
True
)
else:
# Although we expect every room to have a create event (even
# past unknown room versions since we haven't supported one
# without it), there seem to be some corrupted rooms in
# practice that don't have the create event in the
# `current_state_events` table. The create event does exist
# in the events table though. We'll just say that we don't
# know the state for these rooms and continue on with our
# day.
sliding_sync_membership_snapshots_insert_map["has_known_state"] = (
False
)
elif membership in (Membership.INVITE, Membership.KNOCK) or ( elif membership in (Membership.INVITE, Membership.KNOCK) or (
membership == Membership.LEAVE and is_outlier membership == Membership.LEAVE and is_outlier
): ):