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

Transfer alias mappings when joining an upgraded room #6946

Merged
merged 8 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
1 change: 1 addition & 0 deletions changelog.d/6946.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Transfer alias mappings on room upgrade.
3 changes: 3 additions & 0 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ def transfer_room_state_on_room_upgrade(self, old_room_id, room_id):
yield self.store.set_room_is_public(old_room_id, False)
yield self.store.set_room_is_public(room_id, True)

# Transfer alias mappings in the room directory
yield self.store.update_aliases_for_room(old_room_id, room_id)

# Check if any groups we own contain the predecessor room
local_group_ids = yield self.store.get_local_groups_for_room(old_room_id)
for group_id in local_group_ids:
Expand Down
25 changes: 22 additions & 3 deletions synapse/storage/data_stores/main/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from collections import namedtuple
from typing import Optional

from twisted.internet import defer

Expand Down Expand Up @@ -159,10 +160,28 @@ def _delete_room_alias_txn(self, txn, room_alias):

return room_id

def update_aliases_for_room(self, old_room_id, new_room_id, creator):
def update_aliases_for_room(
self, old_room_id: str, new_room_id: str, creator: Optional[str] = None,
):
"""Repoint the aliases from one room to another
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved

Args:
old_room_id:
new_room_id:
creator: The creator of the alias mapping. If None, don't update
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
"""

def _update_aliases_for_room_txn(txn):
sql = "UPDATE room_aliases SET room_id = ?, creator = ? WHERE room_id = ?"
txn.execute(sql, (new_room_id, creator, old_room_id))
update_creator_sql = ""
sql_params = (new_room_id, old_room_id)
if creator:
update_creator_sql = ", creator = ?"
sql_params = (new_room_id, creator, old_room_id)

sql = "UPDATE room_aliases SET room_id = ? %s WHERE room_id = ?" % (
update_creator_sql,
)
txn.execute(sql, sql_params)
self._invalidate_cache_and_stream(
txn, self.get_aliases_for_room, (old_room_id,)
)
Expand Down