mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-27 09:58:41 +00:00
Sliding Sync: No need to sort if the range is large enough to cover all of the rooms (#17731)
Some checks are pending
Build docker images / build (push) Waiting to run
Deploy the documentation / Calculate variables for GitHub Pages deployment (push) Waiting to run
Deploy the documentation / GitHub Pages (push) Blocked by required conditions
Build release artifacts / Calculate list of debian distros (push) Waiting to run
Build release artifacts / Build .deb packages (push) Blocked by required conditions
Build release artifacts / Build wheels on ${{ matrix.os }} for ${{ matrix.arch }} (aarch64, ${{ startsWith(github.ref, 'refs/pull/') }}, ubuntu-20.04) (push) Waiting to run
Build release artifacts / Build wheels on ${{ matrix.os }} for ${{ matrix.arch }} (x86_64, ${{ startsWith(github.ref, 'refs/pull/') }}, macos-12) (push) Waiting to run
Build release artifacts / Build wheels on ${{ matrix.os }} for ${{ matrix.arch }} (x86_64, ${{ startsWith(github.ref, 'refs/pull/') }}, ubuntu-20.04) (push) Waiting to run
Build release artifacts / Build sdist (push) Waiting to run
Build release artifacts / Attach assets to release (push) Blocked by required conditions
Tests / changes (push) Waiting to run
Tests / Typechecking (push) Blocked by required conditions
Tests / lint-crlf (push) Waiting to run
Tests / lint-newsfile (push) Waiting to run
Tests / lint-pydantic (push) Blocked by required conditions
Tests / lint-clippy (push) Blocked by required conditions
Tests / lint-clippy-nightly (push) Blocked by required conditions
Tests / lint-rustfmt (push) Blocked by required conditions
Tests / lint-readme (push) Blocked by required conditions
Tests / linting-done (push) Blocked by required conditions
Tests / calculate-test-jobs (push) Blocked by required conditions
Tests / trial (push) Blocked by required conditions
Tests / trial-olddeps (push) Blocked by required conditions
Tests / trial-pypy (all, pypy-3.8) (push) Blocked by required conditions
Tests / sytest (push) Blocked by required conditions
Tests / export-data (push) Blocked by required conditions
Tests / portdb (11, 3.8) (push) Blocked by required conditions
Tests / portdb (15, 3.11) (push) Blocked by required conditions
Tests / complement (monolith, Postgres) (push) Blocked by required conditions
Tests / complement (monolith, SQLite) (push) Blocked by required conditions
Tests / complement (workers, Postgres) (push) Blocked by required conditions
Tests / cargo-test (push) Blocked by required conditions
Tests / cargo-bench (push) Blocked by required conditions
Tests / tests-done (push) Blocked by required conditions
Tests / check-sampleconfig (push) Blocked by required conditions
Tests / check-schema-delta (push) Blocked by required conditions
Tests / check-lockfile (push) Waiting to run
Tests / lint (push) Blocked by required conditions
Some checks are pending
Build docker images / build (push) Waiting to run
Deploy the documentation / Calculate variables for GitHub Pages deployment (push) Waiting to run
Deploy the documentation / GitHub Pages (push) Blocked by required conditions
Build release artifacts / Calculate list of debian distros (push) Waiting to run
Build release artifacts / Build .deb packages (push) Blocked by required conditions
Build release artifacts / Build wheels on ${{ matrix.os }} for ${{ matrix.arch }} (aarch64, ${{ startsWith(github.ref, 'refs/pull/') }}, ubuntu-20.04) (push) Waiting to run
Build release artifacts / Build wheels on ${{ matrix.os }} for ${{ matrix.arch }} (x86_64, ${{ startsWith(github.ref, 'refs/pull/') }}, macos-12) (push) Waiting to run
Build release artifacts / Build wheels on ${{ matrix.os }} for ${{ matrix.arch }} (x86_64, ${{ startsWith(github.ref, 'refs/pull/') }}, ubuntu-20.04) (push) Waiting to run
Build release artifacts / Build sdist (push) Waiting to run
Build release artifacts / Attach assets to release (push) Blocked by required conditions
Tests / changes (push) Waiting to run
Tests / Typechecking (push) Blocked by required conditions
Tests / lint-crlf (push) Waiting to run
Tests / lint-newsfile (push) Waiting to run
Tests / lint-pydantic (push) Blocked by required conditions
Tests / lint-clippy (push) Blocked by required conditions
Tests / lint-clippy-nightly (push) Blocked by required conditions
Tests / lint-rustfmt (push) Blocked by required conditions
Tests / lint-readme (push) Blocked by required conditions
Tests / linting-done (push) Blocked by required conditions
Tests / calculate-test-jobs (push) Blocked by required conditions
Tests / trial (push) Blocked by required conditions
Tests / trial-olddeps (push) Blocked by required conditions
Tests / trial-pypy (all, pypy-3.8) (push) Blocked by required conditions
Tests / sytest (push) Blocked by required conditions
Tests / export-data (push) Blocked by required conditions
Tests / portdb (11, 3.8) (push) Blocked by required conditions
Tests / portdb (15, 3.11) (push) Blocked by required conditions
Tests / complement (monolith, Postgres) (push) Blocked by required conditions
Tests / complement (monolith, SQLite) (push) Blocked by required conditions
Tests / complement (workers, Postgres) (push) Blocked by required conditions
Tests / cargo-test (push) Blocked by required conditions
Tests / cargo-bench (push) Blocked by required conditions
Tests / tests-done (push) Blocked by required conditions
Tests / check-sampleconfig (push) Blocked by required conditions
Tests / check-schema-delta (push) Blocked by required conditions
Tests / check-lockfile (push) Waiting to run
Tests / lint (push) Blocked by required conditions
No need to sort if the range is large enough to cover all of the rooms in the list. Previously, we would only do this optimization if the range was exactly large enough. Follow-up to https://github.com/element-hq/synapse/pull/17672
This commit is contained in:
parent
faf5b40520
commit
a9c0e27eb7
1
changelog.d/17731.misc
Normal file
1
changelog.d/17731.misc
Normal file
|
@ -0,0 +1 @@
|
|||
Small performance improvement in speeding up Sliding Sync.
|
|
@ -373,8 +373,18 @@ class SlidingSyncRoomLists:
|
|||
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.
|
||||
# Optimization: If we are asking for the full range, we don't
|
||||
# need to sort the list.
|
||||
if (
|
||||
# We're looking for a single range that covers the entire list
|
||||
len(list_config.ranges) == 1
|
||||
# Range starts at 0
|
||||
and list_config.ranges[0][0] == 0
|
||||
# And the range extends to the end of the list or more. Each
|
||||
# side is inclusive.
|
||||
and list_config.ranges[0][1]
|
||||
>= len(filtered_sync_room_map) - 1
|
||||
):
|
||||
sorted_room_info: List[RoomsForUserType] = list(
|
||||
filtered_sync_room_map.values()
|
||||
)
|
||||
|
|
|
@ -230,32 +230,21 @@ class SlidingSyncFiltersTestCase(SlidingSyncBase):
|
|||
response_body, from_token = self.do_sync(sync_body, tok=user1_tok)
|
||||
|
||||
# Make sure the response has the lists we requested
|
||||
self.assertListEqual(
|
||||
list(response_body["lists"].keys()),
|
||||
["all-list", "foo-list"],
|
||||
self.assertIncludes(
|
||||
response_body["lists"].keys(),
|
||||
{"all-list", "foo-list"},
|
||||
)
|
||||
|
||||
# Make sure the lists have the correct rooms
|
||||
self.assertListEqual(
|
||||
list(response_body["lists"]["all-list"]["ops"]),
|
||||
[
|
||||
{
|
||||
"op": "SYNC",
|
||||
"range": [0, 99],
|
||||
"room_ids": [space_room_id, room_id],
|
||||
}
|
||||
],
|
||||
self.assertIncludes(
|
||||
set(response_body["lists"]["all-list"]["ops"][0]["room_ids"]),
|
||||
{space_room_id, room_id},
|
||||
exact=True,
|
||||
)
|
||||
self.assertListEqual(
|
||||
list(response_body["lists"]["foo-list"]["ops"]),
|
||||
[
|
||||
{
|
||||
"op": "SYNC",
|
||||
"range": [0, 99],
|
||||
"room_ids": [space_room_id],
|
||||
}
|
||||
],
|
||||
self.assertIncludes(
|
||||
set(response_body["lists"]["foo-list"]["ops"][0]["room_ids"]),
|
||||
{space_room_id},
|
||||
exact=True,
|
||||
)
|
||||
|
||||
# Everyone leaves the encrypted space room
|
||||
|
@ -284,26 +273,23 @@ class SlidingSyncFiltersTestCase(SlidingSyncBase):
|
|||
}
|
||||
response_body, _ = self.do_sync(sync_body, since=from_token, tok=user1_tok)
|
||||
|
||||
# Make sure the lists have the correct rooms even though we `newly_left`
|
||||
self.assertListEqual(
|
||||
list(response_body["lists"]["all-list"]["ops"]),
|
||||
[
|
||||
{
|
||||
"op": "SYNC",
|
||||
"range": [0, 99],
|
||||
"room_ids": [space_room_id, room_id],
|
||||
}
|
||||
],
|
||||
# Make sure the response has the lists we requested
|
||||
self.assertIncludes(
|
||||
response_body["lists"].keys(),
|
||||
{"all-list", "foo-list"},
|
||||
exact=True,
|
||||
)
|
||||
self.assertListEqual(
|
||||
list(response_body["lists"]["foo-list"]["ops"]),
|
||||
[
|
||||
{
|
||||
"op": "SYNC",
|
||||
"range": [0, 99],
|
||||
"room_ids": [space_room_id],
|
||||
}
|
||||
],
|
||||
|
||||
# Make sure the lists have the correct rooms even though we `newly_left`
|
||||
self.assertIncludes(
|
||||
set(response_body["lists"]["all-list"]["ops"][0]["room_ids"]),
|
||||
{space_room_id, room_id},
|
||||
exact=True,
|
||||
)
|
||||
self.assertIncludes(
|
||||
set(response_body["lists"]["foo-list"]["ops"][0]["room_ids"]),
|
||||
{space_room_id},
|
||||
exact=True,
|
||||
)
|
||||
|
||||
def test_filters_is_dm(self) -> None:
|
||||
|
|
|
@ -935,7 +935,8 @@ class SlidingSyncRoomsMetaTestCase(SlidingSyncBase):
|
|||
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.
|
||||
# Note that we don't sort the rooms when the range includes all of the rooms, so
|
||||
# we just assert that the rooms are included
|
||||
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
|
||||
|
|
|
@ -797,7 +797,38 @@ class SlidingSyncTestCase(SlidingSyncBase):
|
|||
self.helper.send(room_id1, "activity in room1", tok=user1_tok)
|
||||
self.helper.send(room_id2, "activity in room2", tok=user1_tok)
|
||||
|
||||
# Make the Sliding Sync request
|
||||
# Make the Sliding Sync request where the range includes *some* of the rooms
|
||||
sync_body = {
|
||||
"lists": {
|
||||
"foo-list": {
|
||||
"ranges": [[0, 1]],
|
||||
"required_state": [],
|
||||
"timeline_limit": 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
response_body, _ = self.do_sync(sync_body, tok=user1_tok)
|
||||
|
||||
# Make sure it has the foo-list we requested
|
||||
self.assertIncludes(
|
||||
response_body["lists"].keys(),
|
||||
{"foo-list"},
|
||||
)
|
||||
# Make sure the list is sorted in the way we expect (we only sort when the range
|
||||
# doesn't include all of the room)
|
||||
self.assertListEqual(
|
||||
list(response_body["lists"]["foo-list"]["ops"]),
|
||||
[
|
||||
{
|
||||
"op": "SYNC",
|
||||
"range": [0, 1],
|
||||
"room_ids": [room_id2, room_id1],
|
||||
}
|
||||
],
|
||||
response_body["lists"]["foo-list"],
|
||||
)
|
||||
|
||||
# Make the Sliding Sync request where the range includes *all* of the rooms
|
||||
sync_body = {
|
||||
"lists": {
|
||||
"foo-list": {
|
||||
|
@ -810,24 +841,24 @@ class SlidingSyncTestCase(SlidingSyncBase):
|
|||
response_body, _ = self.do_sync(sync_body, tok=user1_tok)
|
||||
|
||||
# Make sure it has the foo-list we requested
|
||||
self.assertListEqual(
|
||||
list(response_body["lists"].keys()),
|
||||
["foo-list"],
|
||||
self.assertIncludes(
|
||||
response_body["lists"].keys(),
|
||||
{"foo-list"},
|
||||
)
|
||||
|
||||
# Make sure the list is sorted in the way we expect
|
||||
self.assertListEqual(
|
||||
list(response_body["lists"]["foo-list"]["ops"]),
|
||||
[
|
||||
{
|
||||
"op": "SYNC",
|
||||
"range": [0, 99],
|
||||
"room_ids": [room_id2, room_id1, room_id3],
|
||||
}
|
||||
],
|
||||
# Since the range includes all of the rooms, we don't sort the list
|
||||
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, 99])
|
||||
# Note that we don't sort the rooms when the range includes all of the rooms, so
|
||||
# we just assert that the rooms are included
|
||||
self.assertIncludes(
|
||||
set(op["room_ids"]), {room_id1, room_id2, room_id3}, exact=True
|
||||
)
|
||||
|
||||
def test_sliced_windows(self) -> None:
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue