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

Commit

Permalink
Always return max stream ID from remove account data repl cmds
Browse files Browse the repository at this point in the history
...instead of returning None when there was not actually any account
data to delete.

This means that in the case of a replication call to remove account data
that didn't exist, the replication response body is now {max_stream_id:
current_stream_id} instead of {max_stream_id: None}.
  • Loading branch information
anoadragon453 committed Mar 2, 2023
1 parent c90597f commit e0ae9cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
6 changes: 0 additions & 6 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 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 @@ -585,7 +585,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 @@ -637,15 +637,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 @@ -753,7 +751,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 @@ -840,14 +838,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 e0ae9cf

Please sign in to comment.