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

Start application service stream token tracking from 1 #12193

Merged
merged 7 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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/12193.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug where excess presence events may be sent to an application service after it is initially configured.
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ async def get_new_events(
# We'll actually pull the presence updates for these users at the end.
interested_and_updated_users: Union[Set[str], FrozenSet[str]] = set()

if from_key:
if from_key is not None:
# First get all users that have had a presence update
updated_users = stream_change_cache.get_all_entities_changed(from_key)

Expand Down
3 changes: 2 additions & 1 deletion synapse/storage/databases/main/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ def get_type_stream_id_for_appservice_txn(txn):
)
last_stream_id = txn.fetchone()
if last_stream_id is None or last_stream_id[0] is None: # no row exists
return 0
# stream tokens always start from 1
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
return 1
else:
return int(last_stream_id[0])

Expand Down
4 changes: 2 additions & 2 deletions tests/storage/test_appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,12 @@ def test_get_type_stream_id_for_appservice_no_value(self) -> None:
value = self.get_success(
self.store.get_type_stream_id_for_appservice(self.service, "read_receipt")
)
self.assertEqual(value, 0)
self.assertEqual(value, 1)

value = self.get_success(
self.store.get_type_stream_id_for_appservice(self.service, "presence")
)
self.assertEqual(value, 0)
self.assertEqual(value, 1)

def test_get_type_stream_id_for_appservice_invalid_type(self) -> None:
self.get_failure(
Expand Down