This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
add a cache to have_seen_event #9953
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d5fd6b0
add a cache to have_seen_event
richvdh dd407a7
Merge remote-tracking branch 'origin/develop' into rav/have_seen_even…
richvdh dbe8659
Address review comments
richvdh 70cb739
update news files
richvdh ae20c8d
Fix brokenness, address review comments, add tests
richvdh c8cf20c
fix test breakage under postgres
richvdh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve performance of incoming federation transactions in large rooms. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve performance of incoming federation transactions in large rooms. |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2021 The Matrix.org Foundation C.I.C. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2021 The Matrix.org Foundation C.I.C. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Copyright 2021 The Matrix.org Foundation C.I.C. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import json | ||
|
||
from synapse.logging.context import LoggingContext | ||
from synapse.storage.databases.main.events_worker import EventsWorkerStore | ||
|
||
from tests import unittest | ||
|
||
|
||
class HaveSeenEventsTestCase(unittest.HomeserverTestCase): | ||
def prepare(self, reactor, clock, hs): | ||
self.store: EventsWorkerStore = hs.get_datastore() | ||
|
||
# insert some test data | ||
for rid in ("room1", "room2"): | ||
self.get_success( | ||
self.store.db_pool.simple_insert( | ||
"rooms", | ||
{"room_id": rid, "room_version": 4}, | ||
) | ||
) | ||
|
||
for idx, (rid, eid) in enumerate( | ||
( | ||
("room1", "event10"), | ||
("room1", "event11"), | ||
("room1", "event12"), | ||
("room2", "event20"), | ||
) | ||
): | ||
self.get_success( | ||
self.store.db_pool.simple_insert( | ||
"events", | ||
{ | ||
"event_id": eid, | ||
"room_id": rid, | ||
"topological_ordering": idx, | ||
"stream_ordering": idx, | ||
"type": "test", | ||
"processed": True, | ||
"outlier": False, | ||
}, | ||
) | ||
) | ||
self.get_success( | ||
self.store.db_pool.simple_insert( | ||
"event_json", | ||
{ | ||
"event_id": eid, | ||
"room_id": rid, | ||
"json": json.dumps({"type": "test", "room_id": rid}), | ||
"internal_metadata": "{}", | ||
"format_version": 3, | ||
}, | ||
) | ||
) | ||
|
||
def test_simple(self): | ||
with LoggingContext(name="test") as ctx: | ||
res = self.get_success( | ||
self.store.have_seen_events("room1", ["event10", "event19"]) | ||
) | ||
self.assertEquals(res, {"event10"}) | ||
|
||
# that should result in a single db query | ||
self.assertEquals(ctx.get_resource_usage().db_txn_count, 1) | ||
|
||
# a second lookup of the same events should cause no queries | ||
with LoggingContext(name="test") as ctx: | ||
res = self.get_success( | ||
self.store.have_seen_events("room1", ["event10", "event19"]) | ||
) | ||
self.assertEquals(res, {"event10"}) | ||
self.assertEquals(ctx.get_resource_usage().db_txn_count, 0) | ||
|
||
def test_query_via_event_cache(self): | ||
# fetch an event into the event cache | ||
self.get_success(self.store.get_event("event10")) | ||
|
||
# looking it up should now cause no db hits | ||
with LoggingContext(name="test") as ctx: | ||
res = self.get_success(self.store.have_seen_events("room1", ["event10"])) | ||
self.assertEquals(res, {"event10"}) | ||
self.assertEquals(ctx.get_resource_usage().db_txn_count, 0) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.