Skip to content

Commit

Permalink
Merge branch 'madlittlemods/sliding-sync-pre-populate-room-meta-data'…
Browse files Browse the repository at this point in the history
… into erikj/ss_room_lists_new_tables
  • Loading branch information
erikjohnston committed Aug 28, 2024
2 parents 42f43a8 + 90d0e03 commit 1226bb4
Show file tree
Hide file tree
Showing 22 changed files with 7,235 additions and 109 deletions.
1 change: 1 addition & 0 deletions changelog.d/17512.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pre-populate room data used in experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync` endpoint for quick filtering/sorting.
5 changes: 5 additions & 0 deletions synapse/_scripts/synapse_port_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@
"remote_media_cache": ["authenticated"],
"room_stats_state": ["is_federatable"],
"rooms": ["is_public", "has_auth_chain_index"],
"sliding_sync_joined_rooms": ["is_encrypted"],
"sliding_sync_membership_snapshots": [
"has_known_state",
"is_encrypted",
],
"users": ["shadow_banned", "approved", "locked", "suspended"],
"un_partial_stated_event_stream": ["rejection_status_changed"],
"users_who_share_rooms": ["share_private"],
Expand Down
2 changes: 2 additions & 0 deletions synapse/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ class EventContentFields:
# `m.room.encryption`` algorithm field
ENCRYPTION_ALGORITHM: Final = "algorithm"

TOMBSTONE_SUCCESSOR_ROOM: Final = "replacement_room"


class EventUnsignedContentFields:
"""Fields found inside the 'unsigned' data on events"""
Expand Down
22 changes: 8 additions & 14 deletions synapse/handlers/sliding_sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@
StreamKeyType,
StreamToken,
)
from synapse.types.handlers import SlidingSyncConfig, SlidingSyncResult
from synapse.types.handlers import (
SLIDING_SYNC_DEFAULT_BUMP_EVENT_TYPES,
SlidingSyncConfig,
SlidingSyncResult,
)
from synapse.types.state import StateFilter
from synapse.util.async_helpers import concurrently_execute
from synapse.visibility import filter_events_for_client
Expand All @@ -75,18 +79,6 @@
)


# The event types that clients should consider as new activity.
DEFAULT_BUMP_EVENT_TYPES = {
EventTypes.Create,
EventTypes.Message,
EventTypes.Encrypted,
EventTypes.Sticker,
EventTypes.CallInvite,
EventTypes.PollStart,
EventTypes.LiveLocationShareStart,
}


class SlidingSyncHandler:
def __init__(self, hs: "HomeServer"):
self.clock = hs.get_clock()
Expand Down Expand Up @@ -986,7 +978,9 @@ async def get_room_sync_data(
# Figure out the last bump event in the room
last_bump_event_result = (
await self.store.get_last_event_pos_in_room_before_stream_ordering(
room_id, to_token.room_key, event_types=DEFAULT_BUMP_EVENT_TYPES
room_id,
to_token.room_key,
event_types=SLIDING_SYNC_DEFAULT_BUMP_EVENT_TYPES,
)
)

Expand Down
9 changes: 8 additions & 1 deletion synapse/storage/controllers/persist_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,15 @@ async def _update_current_state(
"""
state = await self._calculate_current_state(room_id)
delta = await self._calculate_state_delta(room_id, state)
sliding_sync_table_changes = (
await self.persist_events_store._calculate_sliding_sync_table_changes(
room_id, [], delta
)
)

await self.persist_events_store.update_current_state(room_id, delta)
await self.persist_events_store.update_current_state(
room_id, delta, sliding_sync_table_changes
)

async def _calculate_current_state(self, room_id: str) -> StateMap[str]:
"""Calculate the current state of a room, based on the forward extremities
Expand Down
29 changes: 15 additions & 14 deletions synapse/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
Iterable,
Iterator,
List,
Mapping,
Optional,
Sequence,
Tuple,
Expand Down Expand Up @@ -1254,9 +1255,9 @@ def simple_upsert_txn(
self,
txn: LoggingTransaction,
table: str,
keyvalues: Dict[str, Any],
values: Dict[str, Any],
insertion_values: Optional[Dict[str, Any]] = None,
keyvalues: Mapping[str, Any],
values: Mapping[str, Any],
insertion_values: Optional[Mapping[str, Any]] = None,
where_clause: Optional[str] = None,
) -> bool:
"""
Expand Down Expand Up @@ -1299,9 +1300,9 @@ def simple_upsert_txn_emulated(
self,
txn: LoggingTransaction,
table: str,
keyvalues: Dict[str, Any],
values: Dict[str, Any],
insertion_values: Optional[Dict[str, Any]] = None,
keyvalues: Mapping[str, Any],
values: Mapping[str, Any],
insertion_values: Optional[Mapping[str, Any]] = None,
where_clause: Optional[str] = None,
lock: bool = True,
) -> bool:
Expand All @@ -1322,7 +1323,7 @@ def simple_upsert_txn_emulated(

if lock:
# We need to lock the table :(
self.engine.lock_table(txn, table)
txn.database_engine.lock_table(txn, table)

def _getwhere(key: str) -> str:
# If the value we're passing in is None (aka NULL), we need to use
Expand Down Expand Up @@ -1376,13 +1377,13 @@ def _getwhere(key: str) -> str:
# successfully inserted
return True

@staticmethod
def simple_upsert_txn_native_upsert(
self,
txn: LoggingTransaction,
table: str,
keyvalues: Dict[str, Any],
values: Dict[str, Any],
insertion_values: Optional[Dict[str, Any]] = None,
keyvalues: Mapping[str, Any],
values: Mapping[str, Any],
insertion_values: Optional[Mapping[str, Any]] = None,
where_clause: Optional[str] = None,
) -> bool:
"""
Expand Down Expand Up @@ -1535,8 +1536,8 @@ def simple_upsert_many_txn_emulated(

self.simple_upsert_txn_emulated(txn, table, _keys, _vals, lock=False)

@staticmethod
def simple_upsert_many_txn_native_upsert(
self,
txn: LoggingTransaction,
table: str,
key_names: Collection[str],
Expand Down Expand Up @@ -1966,8 +1967,8 @@ async def simple_update(
def simple_update_txn(
txn: LoggingTransaction,
table: str,
keyvalues: Dict[str, Any],
updatevalues: Dict[str, Any],
keyvalues: Mapping[str, Any],
updatevalues: Mapping[str, Any],
) -> int:
"""
Update rows in the given database table.
Expand Down
Loading

0 comments on commit 1226bb4

Please sign in to comment.