mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Small performance improvements for sliding sync (#17672)
A couple of small performance improvements for sliding sync.
This commit is contained in:
parent
786de8570b
commit
a708e1afd0
1
changelog.d/17672.misc
Normal file
1
changelog.d/17672.misc
Normal file
@ -0,0 +1 @@
|
||||
Small performance improvement in speeding up sliding sync.
|
@ -350,13 +350,18 @@ class SlidingSyncRoomLists:
|
||||
|
||||
all_rooms.update(filtered_sync_room_map)
|
||||
|
||||
ops: List[SlidingSyncResult.SlidingWindowList.Operation] = []
|
||||
|
||||
if list_config.ranges:
|
||||
if list_config.ranges == [(0, len(filtered_sync_room_map) - 1)]:
|
||||
# If we are asking for the full range, we don't need to sort the list.
|
||||
sorted_room_info = list(filtered_sync_room_map.values())
|
||||
else:
|
||||
# Sort the list
|
||||
sorted_room_info = await self.sort_rooms_using_tables(
|
||||
filtered_sync_room_map, to_token
|
||||
)
|
||||
|
||||
ops: List[SlidingSyncResult.SlidingWindowList.Operation] = []
|
||||
if list_config.ranges:
|
||||
for range in list_config.ranges:
|
||||
room_ids_in_list: List[str] = []
|
||||
|
||||
|
@ -19,6 +19,7 @@ from enum import Enum
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
AbstractSet,
|
||||
Any,
|
||||
Callable,
|
||||
Dict,
|
||||
Final,
|
||||
@ -703,7 +704,12 @@ class HaveSentRoom(Generic[T]):
|
||||
|
||||
@staticmethod
|
||||
def never() -> "HaveSentRoom[T]":
|
||||
return HaveSentRoom(HaveSentRoomFlag.NEVER, None)
|
||||
# We use a singleton to avoid repeatedly instantiating new `never`
|
||||
# values.
|
||||
return _HAVE_SENT_ROOM_NEVER
|
||||
|
||||
|
||||
_HAVE_SENT_ROOM_NEVER: HaveSentRoom[Any] = HaveSentRoom(HaveSentRoomFlag.NEVER, None)
|
||||
|
||||
|
||||
@attr.s(auto_attribs=True, slots=True, frozen=True)
|
||||
|
@ -588,19 +588,16 @@ class SlidingSyncRoomsMetaTestCase(SlidingSyncBase):
|
||||
)
|
||||
|
||||
# Make sure the list includes the rooms in the right order
|
||||
self.assertListEqual(
|
||||
list(response_body["lists"]["foo-list"]["ops"]),
|
||||
[
|
||||
{
|
||||
"op": "SYNC",
|
||||
"range": [0, 1],
|
||||
# room1 sorts before room2 because it has the latest event (the
|
||||
# reaction)
|
||||
"room_ids": [room_id1, room_id2],
|
||||
}
|
||||
],
|
||||
self.assertEqual(
|
||||
len(response_body["lists"]["foo-list"]["ops"]),
|
||||
1,
|
||||
response_body["lists"]["foo-list"],
|
||||
)
|
||||
op = response_body["lists"]["foo-list"]["ops"][0]
|
||||
self.assertEqual(op["op"], "SYNC")
|
||||
self.assertEqual(op["range"], [0, 1])
|
||||
# Note that we don't order the ops anymore, so we need to compare sets.
|
||||
self.assertIncludes(set(op["room_ids"]), {room_id1, room_id2}, exact=True)
|
||||
|
||||
# The `bump_stamp` for room1 should point at the latest message (not the
|
||||
# reaction since it's not one of the `DEFAULT_BUMP_EVENT_TYPES`)
|
||||
|
Loading…
Reference in New Issue
Block a user