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
Pull out less state when handling gaps mk2 #12852
Merged
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
99b350e
Change compute_event_context to take state_ids
erikjohnston 05474e9
Change _process_received_pdu
erikjohnston 35a4614
Change _resolve_state_at_missing_prevs
erikjohnston ea9063d
Add a get_metadata_for_events DB func
erikjohnston 7a9586e
_get_state_after_missing_prev_event
erikjohnston 37b9c33
Change MessageHandler
erikjohnston 0fe4092
Fix tests
erikjohnston 9376b9a
Newsfile
erikjohnston 71907fd
Fix tests
erikjohnston f9ba81b
Apply suggestions from code review
erikjohnston edcd824
Code review comments
erikjohnston 72a783e
Merge remote-tracking branch 'origin/develop' into erikj/less_state_o…
erikjohnston 4343d35
Update synapse/storage/databases/main/state.py
erikjohnston a593b2d
Merge remote-tracking branch 'origin/develop' into erikj/less_state_o…
erikjohnston 9e43239
Fix style
erikjohnston 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 @@ | ||
| Pull out less state when handling gaps in room DAG. |
Large diffs are not rendered by default.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
| import logging | ||
| from typing import TYPE_CHECKING, Collection, Dict, Iterable, Optional, Set, Tuple | ||
|
|
||
| import attr | ||
|
|
||
| from synapse.api.constants import EventTypes, Membership | ||
| from synapse.api.errors import NotFoundError, UnsupportedRoomVersionError | ||
| from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersion | ||
|
|
@@ -26,13 +28,15 @@ | |
| DatabasePool, | ||
| LoggingDatabaseConnection, | ||
| LoggingTransaction, | ||
| make_in_list_sql_clause, | ||
| ) | ||
| from synapse.storage.databases.main.events_worker import EventsWorkerStore | ||
| from synapse.storage.databases.main.roommember import RoomMemberWorkerStore | ||
| from synapse.storage.state import StateFilter | ||
| from synapse.types import JsonDict, JsonMapping, StateMap | ||
| from synapse.util.caches import intern_string | ||
| from synapse.util.caches.descriptors import cached, cachedList | ||
| from synapse.util.iterutils import batch_iter | ||
|
|
||
| if TYPE_CHECKING: | ||
| from synapse.server import HomeServer | ||
|
|
@@ -43,6 +47,15 @@ | |
| MAX_STATE_DELTA_HOPS = 100 | ||
|
|
||
|
|
||
| @attr.s(slots=True, frozen=True, auto_attribs=True) | ||
| class EventMetadata: | ||
| """Returned by `get_metadata_for_events`""" | ||
|
|
||
| room_id: str | ||
| event_type: str | ||
| state_key: Optional[str] | ||
|
|
||
|
|
||
| def _retrieve_and_check_room_version(room_id: str, room_version_id: str) -> RoomVersion: | ||
| v = KNOWN_ROOM_VERSIONS.get(room_version_id) | ||
| if not v: | ||
|
|
@@ -133,6 +146,50 @@ def get_room_version_id_txn(self, txn: LoggingTransaction, room_id: str) -> str: | |
|
|
||
| return room_version | ||
|
|
||
| async def get_metadata_for_events( | ||
| self, event_ids: Collection[str] | ||
| ) -> Dict[str, EventMetadata]: | ||
| """Get some metadata (room_id, type, state_key) for the given events. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree this isn't a great name. What I really want to call it is "pull out basic info about the event without having to pull out and parse everything"
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, fair. I can't really think of a better name right now either. |
||
|
|
||
| This method is a faster alternative than fetching the full events from | ||
| the DB, and should be used when the full event is not needed. | ||
|
|
||
| Returns metadata for rejected and redacted events. Events that have not | ||
| been persisted are omitted from the returned dict. | ||
| """ | ||
|
|
||
| def get_metadata_for_events_txn( | ||
| txn: LoggingTransaction, | ||
| batch_ids: Collection[str], | ||
| ) -> Dict[str, EventMetadata]: | ||
| clause, args = make_in_list_sql_clause( | ||
| self.database_engine, "e.event_id", batch_ids | ||
| ) | ||
|
|
||
| sql = f""" | ||
| SELECT e.event_id, e.room_id, e.type, e.state_key FROM events AS e | ||
| LEFT JOIN state_events USING (event_id) | ||
| WHERE {clause} | ||
| """ | ||
|
|
||
| txn.execute(sql, args) | ||
| return { | ||
| event_id: EventMetadata( | ||
| room_id=room_id, event_type=event_type, state_key=state_key | ||
| ) | ||
| for event_id, room_id, event_type, state_key in txn | ||
| } | ||
|
|
||
| result_map: Dict[str, EventMetadata] = {} | ||
| for batch_ids in batch_iter(event_ids, 1000): | ||
| result_map = await self.db_pool.runInteraction( | ||
| "get_metadata_for_events", | ||
| get_metadata_for_events_txn, | ||
| batch_ids=batch_ids, | ||
| ) | ||
|
erikjohnston marked this conversation as resolved.
Outdated
|
||
|
|
||
| return result_map | ||
|
|
||
| async def get_room_predecessor(self, room_id: str) -> Optional[JsonMapping]: | ||
| """Get the predecessor of an upgraded room if it exists. | ||
| Otherwise return None. | ||
|
|
||
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
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.