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

Commit

Permalink
Experimental MSC3890 Implementation: Fix deleting account data when u…
Browse files Browse the repository at this point in the history
…sing an account data writer worker (#14869)
  • Loading branch information
anoadragon453 authored Mar 3, 2023
1 parent 1eea662 commit 15e975f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
1 change: 1 addition & 0 deletions changelog.d/14869.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug introduced in v1.75.0rc1 that caused experimental support for deleting account data to raise an internal server error while using an account data writer worker.
7 changes: 0 additions & 7 deletions synapse/handlers/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ async def remove_account_data_for_room(
max_stream_id = await self._store.remove_account_data_for_room(
user_id, room_id, account_data_type
)
if max_stream_id is None:
# The referenced account data did not exist, so no delete occurred.
return None

self._notifier.on_new_event(
StreamKeyType.ACCOUNT_DATA, max_stream_id, users=[user_id]
Expand Down Expand Up @@ -230,9 +227,6 @@ async def remove_account_data_for_user(
max_stream_id = await self._store.remove_account_data_for_user(
user_id, account_data_type
)
if max_stream_id is None:
# The referenced account data did not exist, so no delete occurred.
return None

self._notifier.on_new_event(
StreamKeyType.ACCOUNT_DATA, max_stream_id, users=[user_id]
Expand All @@ -248,7 +242,6 @@ async def remove_account_data_for_user(
instance_name=random.choice(self._account_data_writers),
user_id=user_id,
account_data_type=account_data_type,
content={},
)
return response["max_stream_id"]

Expand Down
34 changes: 15 additions & 19 deletions synapse/storage/databases/main/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ async def add_account_data_to_room(

async def remove_account_data_for_room(
self, user_id: str, room_id: str, account_data_type: str
) -> Optional[int]:
) -> int:
"""Delete the room account data for the user of a given type.
Args:
Expand Down Expand Up @@ -632,15 +632,13 @@ def _remove_account_data_for_room_txn(
next_id,
)

if not row_updated:
return None

self._account_data_stream_cache.entity_has_changed(user_id, next_id)
self.get_room_account_data_for_user.invalidate((user_id,))
self.get_account_data_for_room.invalidate((user_id, room_id))
self.get_account_data_for_room_and_type.prefill(
(user_id, room_id, account_data_type), {}
)
if row_updated:
self._account_data_stream_cache.entity_has_changed(user_id, next_id)
self.get_room_account_data_for_user.invalidate((user_id,))
self.get_account_data_for_room.invalidate((user_id, room_id))
self.get_account_data_for_room_and_type.prefill(
(user_id, room_id, account_data_type), {}
)

return self._account_data_id_gen.get_current_token()

Expand Down Expand Up @@ -747,7 +745,7 @@ async def remove_account_data_for_user(
self,
user_id: str,
account_data_type: str,
) -> Optional[int]:
) -> int:
"""
Delete a single piece of user account data by type.
Expand Down Expand Up @@ -833,14 +831,12 @@ def _remove_account_data_for_user_txn(
next_id,
)

if not row_updated:
return None

self._account_data_stream_cache.entity_has_changed(user_id, next_id)
self.get_global_account_data_for_user.invalidate((user_id,))
self.get_global_account_data_by_type_for_user.prefill(
(user_id, account_data_type), {}
)
if row_updated:
self._account_data_stream_cache.entity_has_changed(user_id, next_id)
self.get_global_account_data_for_user.invalidate((user_id,))
self.get_global_account_data_by_type_for_user.prefill(
(user_id, account_data_type), {}
)

return self._account_data_id_gen.get_current_token()

Expand Down

0 comments on commit 15e975f

Please sign in to comment.