diff options
author | Erik Johnston <erik@matrix.org> | 2024-07-11 11:43:30 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2024-07-11 11:43:30 +0100 |
commit | d4dd9163d72a6ee0db5fe16996643700791babf2 (patch) | |
tree | 920071acf3470208d245cb0b647937b37cc00250 /synapse | |
parent | New table (diff) | |
download | synapse-d4dd9163d72a6ee0db5fe16996643700791babf2.tar.xz |
Fixup room types
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/handlers/sliding_sync.py | 25 | ||||
-rw-r--r-- | synapse/storage/databases/main/room.py | 24 |
2 files changed, 36 insertions, 13 deletions
diff --git a/synapse/handlers/sliding_sync.py b/synapse/handlers/sliding_sync.py index 3cf42bd14d..02a69d6e02 100644 --- a/synapse/handlers/sliding_sync.py +++ b/synapse/handlers/sliding_sync.py @@ -448,6 +448,15 @@ class SlidingSyncHandler: # Apply filters filtered_sync_room_map = sync_room_map + if list_config.filters: + + filtered_sync_room_map = await self.filter_rooms( + sync_config.user, + filtered_sync_room_map, + list_config.filters, + to_token, + ) + # Sort the list sorted_room_info = await self.sort_rooms( filtered_sync_room_map, to_token @@ -494,14 +503,6 @@ class SlidingSyncHandler: if partial_state_room_map.get(room_id) and not lazy_loading: continue - if list_config.filters and not await self.filter_rooms( - sync_config.user, - {room_id: room_membership}, - list_config.filters, - to_token, - ): - continue - # Take the superset of the `RoomSyncConfig` for each room. # # Update our `relevant_room_map` with the room we're going @@ -974,12 +975,10 @@ class SlidingSyncHandler: if filters.room_types is not None or filters.not_room_types is not None: # Make a copy so we don't run into an error: `Set changed size during # iteration`, when we filter out and remove items + + room_types = await self.store.bulk_get_room_type(filtered_room_id_set) for room_id in filtered_room_id_set.copy(): - try: - create_event = await self.store.get_create_event_for_room(room_id) - room_type = create_event.content.get(EventContentFields.ROOM_TYPE) - except: - room_type = None + room_type = room_types.get(room_id) if ( filters.room_types is not None diff --git a/synapse/storage/databases/main/room.py b/synapse/storage/databases/main/room.py index 80a4bf95f2..498a136543 100644 --- a/synapse/storage/databases/main/room.py +++ b/synapse/storage/databases/main/room.py @@ -228,6 +228,30 @@ class RoomWorkerStore(CacheInvalidationWorkerStore): return row return bool(row[0]), bool(row[1]) + @cached(max_entries=10000) + async def get_room_type(self, room_id: str) -> Optional[str]: + # TODO: Upsert room_stats_state on room creation / initial join. + return await self.db_pool.simple_select_one_onecol( + table="room_stats_state", + keyvalues={"room_id": room_id}, + retcol="room_type", + allow_none=True, + desc="get_room_type", + ) + + @cachedList(cached_method_name="get_room_type", list_name="room_ids") + async def bulk_get_room_type( + self, room_ids: StrCollection + ) -> Mapping[str, Optional[str]]: + rows = await self.db_pool.simple_select_many_batch( + table="room_stats_state", + column="room_id", + iterable=room_ids, + retcols=("room_id", "room_type"), + desc="bulk_get_room_type", + ) + return dict(rows) + async def get_room_with_stats(self, room_id: str) -> Optional[RoomStats]: """Retrieve room with statistics. |