Fix only handling the last presence state for each user (#9425)
This is a small bug that I noticed while working on #8956.
We have a for-loop which attempts to strip all presence changes for each user except for the final one, as we don't really care about older presence:
9e19c6aab4/synapse/handlers/presence.py (L368-L371)
`new_states_dict` stores this stripped copy of latest presence state for each user, before it is... put into a new variable `new_state`, which is just overridden by the subsequent for loop.
I believe this was instead meant to override `new_states`. Without doing so, it effectively meant:
1. The for loop had no effect.
2. We were still processing old presence state for users.
This commit is contained in:
parent
53f1c4da81
commit
3e5749b99f
2 changed files with 6 additions and 2 deletions
1
changelog.d/9425.bugfix
Normal file
1
changelog.d/9425.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix a long-standing bug in the deduplication of old presence, resulting in no deduplication.
|
|
@ -349,10 +349,13 @@ class PresenceHandler(BasePresenceHandler):
|
||||||
[self.user_to_current_state[user_id] for user_id in unpersisted]
|
[self.user_to_current_state[user_id] for user_id in unpersisted]
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _update_states(self, new_states):
|
async def _update_states(self, new_states: Iterable[UserPresenceState]) -> None:
|
||||||
"""Updates presence of users. Sets the appropriate timeouts. Pokes
|
"""Updates presence of users. Sets the appropriate timeouts. Pokes
|
||||||
the notifier and federation if and only if the changed presence state
|
the notifier and federation if and only if the changed presence state
|
||||||
should be sent to clients/servers.
|
should be sent to clients/servers.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
new_states: The new user presence state updates to process.
|
||||||
"""
|
"""
|
||||||
now = self.clock.time_msec()
|
now = self.clock.time_msec()
|
||||||
|
|
||||||
|
@ -368,7 +371,7 @@ class PresenceHandler(BasePresenceHandler):
|
||||||
new_states_dict = {}
|
new_states_dict = {}
|
||||||
for new_state in new_states:
|
for new_state in new_states:
|
||||||
new_states_dict[new_state.user_id] = new_state
|
new_states_dict[new_state.user_id] = new_state
|
||||||
new_state = new_states_dict.values()
|
new_states = new_states_dict.values()
|
||||||
|
|
||||||
for new_state in new_states:
|
for new_state in new_states:
|
||||||
user_id = new_state.user_id
|
user_id = new_state.user_id
|
||||||
|
|
Loading…
Reference in a new issue