Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add local_current_membership table #6655

Merged
merged 11 commits into from
Jan 15, 2020
26 changes: 26 additions & 0 deletions synapse/storage/data_stores/main/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,23 @@ def _store_room_members_txn(self, txn, events, backfilled):
),
)

# We also update the `local_current_membership` table with
# latest invite info. This will usually get updated by the
# `current_state_events` handling, unless its an outlier.
if event.internal_metadata.is_outlier():
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
self.db.simple_upsert_txn(
txn,
table="local_current_membership",
keyvalues={
"room_id": event.room_id,
"user_id": event.state_key,
},
values={
"event_id": event.event_id,
"membership": event.membership,
},
)

@defer.inlineCallbacks
def locally_reject_invite(self, user_id, room_id):
sql = (
Expand All @@ -1075,6 +1092,15 @@ def locally_reject_invite(self, user_id, room_id):
def f(txn, stream_ordering):
txn.execute(sql, (stream_ordering, True, room_id, user_id))

# We also clear this entry from `local_current_membership`.
# Ideally we'd point to a leave event, but we don't have one, so
# nevermind.
self.db.simple_delete_txn(
txn,
table="local_current_membership",
keyvalues={"room_id": room_id, "user_id": user_id},
)

with self._stream_id_gen.get_next() as stream_ordering:
yield self.db.runInteraction("locally_reject_invite", f, stream_ordering)

Expand Down
1 change: 1 addition & 0 deletions synapse/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"device_lists_remote_extremeties": "device_lists_remote_extremeties_unique_idx",
"device_lists_remote_cache": "device_lists_remote_cache_unique_idx",
"event_search": "event_search_event_id_idx",
"local_current_membership": "local_current_membership_idx",
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down