Skip to content
Snippets Groups Projects
Unverified Commit a301934f authored by Richard van der Hoff's avatar Richard van der Hoff Committed by GitHub
Browse files

Upsert room version when we join over federation (#6968)

This is intended as a precursor to storing room versions when we receive an
invite over federation, but has the happy side-effect of fixing #3374 at last.

In short: change the store_room with try/except to a proper upsert which
updates the right columns.
parent 4c2ed3f2
No related branches found
No related tags found
No related merge requests found
Fix `duplicate key` error which was logged when rejoining a room over federation.
...@@ -1323,16 +1323,18 @@ class FederationHandler(BaseHandler): ...@@ -1323,16 +1323,18 @@ class FederationHandler(BaseHandler):
logger.debug("do_invite_join event: %s", event) logger.debug("do_invite_join event: %s", event)
try: # if this is the first time we've joined this room, it's time to add
await self.store.store_room( # a row to `rooms` with the correct room version. If there's already a
room_id=room_id, # row there, we should override it, since it may have been populated
room_creator_user_id="", # based on an invite request which lied about the room version.
is_public=False, #
room_version=room_version_obj, # federation_client.send_join has already checked that the room
) # version in the received create event is the same as room_version_obj,
except Exception: # so we can rely on it now.
# FIXME #
pass await self.store.upsert_room_on_join(
room_id=room_id, room_version=room_version_obj,
)
await self._persist_auth_tree( await self._persist_auth_tree(
origin, auth_chain, state, event, room_version_obj origin, auth_chain, state, event, room_version_obj
......
...@@ -954,6 +954,23 @@ class RoomStore(RoomBackgroundUpdateStore, RoomWorkerStore, SearchStore): ...@@ -954,6 +954,23 @@ class RoomStore(RoomBackgroundUpdateStore, RoomWorkerStore, SearchStore):
self.config = hs.config self.config = hs.config
async def upsert_room_on_join(self, room_id: str, room_version: RoomVersion):
"""Ensure that the room is stored in the table
Called when we join a room over federation, and overwrites any room version
currently in the table.
"""
await self.db.simple_upsert(
desc="upsert_room_on_join",
table="rooms",
keyvalues={"room_id": room_id},
values={"room_version": room_version.identifier},
insertion_values={"is_public": False, "creator": ""},
# rooms has a unique constraint on room_id, so no need to lock when doing an
# emulated upsert.
lock=False,
)
@defer.inlineCallbacks @defer.inlineCallbacks
def store_room( def store_room(
self, self,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment