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

Stop writing to the event_txn_id table #16175

Merged
merged 7 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions synapse/storage/databases/main/events_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2072,29 +2072,29 @@ async def get_already_persisted_events(
"""

mapping = {}
txn_id_to_event: Dict[Tuple[str, int, str], str] = {}
txn_id_to_event: Dict[Tuple[str, str, str], str] = {}

for event in events:
token_id = getattr(event.internal_metadata, "token_id", None)
device_id = getattr(event.internal_metadata, "device_id", None)
clokep marked this conversation as resolved.
Show resolved Hide resolved
txn_id = getattr(event.internal_metadata, "txn_id", None)

if token_id and txn_id:
if device_id and txn_id:
# Check if this is a duplicate of an event in the given events.
existing = txn_id_to_event.get((event.room_id, token_id, txn_id))
existing = txn_id_to_event.get((event.room_id, device_id, txn_id))
if existing:
mapping[event.event_id] = existing
continue

# Check if this is a duplicate of an event we've already
# persisted.
existing = await self.get_event_id_from_transaction_id_and_token_id(
event.room_id, event.sender, token_id, txn_id
existing = await self.get_event_id_from_transaction_id_and_device_id(
event.room_id, event.sender, device_id, txn_id
)
if existing:
mapping[event.event_id] = existing
txn_id_to_event[(event.room_id, token_id, txn_id)] = existing
txn_id_to_event[(event.room_id, device_id, txn_id)] = existing
else:
txn_id_to_event[(event.room_id, token_id, txn_id)] = event.event_id
txn_id_to_event[(event.room_id, device_id, txn_id)] = event.event_id

return mapping

Expand Down
15 changes: 4 additions & 11 deletions tests/handlers/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,11 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
self._persist_event_storage_controller = persistence

self.user_id = self.register_user("tester", "foobar")
self.access_token = self.login("tester", "foobar")
self.room_id = self.helper.create_room_as(self.user_id, tok=self.access_token)

info = self.get_success(
self.hs.get_datastores().main.get_user_by_access_token(
self.access_token,
)
)
assert info is not None
self.token_id = info.token_id
device_id = "dev-1"
access_token = self.login("tester", "foobar", device_id=device_id)
self.room_id = self.helper.create_room_as(self.user_id, tok=access_token)

self.requester = create_requester(self.user_id, access_token_id=self.token_id)
self.requester = create_requester(self.user_id, device_id=device_id)

def _create_and_persist_member_event(self) -> Tuple[EventBase, EventContext]:
# Create a member event we can use as an auth_event
Expand Down