From f61c96fdc31cb9b1937c0bdfc82b9b17b7f3e331 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Fri, 2 Aug 2024 09:33:35 -0400 Subject: [PATCH] Check startup delayed state events for same state If on startup there are multiple delayed state events to be sent, do not send multiple events that target the same state key for a room. --- synapse/handlers/delayed_events.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/synapse/handlers/delayed_events.py b/synapse/handlers/delayed_events.py index 04974a95d37..5a4481fb300 100644 --- a/synapse/handlers/delayed_events.py +++ b/synapse/handlers/delayed_events.py @@ -27,6 +27,8 @@ Dict, List, Optional, + Set, + Tuple, ) import attr @@ -100,11 +102,35 @@ async def _schedule_db_events() -> None: events, remaining_timeout_delays = await self.store.process_all_delays( self._get_current_ts() ) - for args in events: + sent_state: Set[Tuple[RoomID, EventType, StateKey]] = set() + for ( + user_localpart, + room_id, + event_type, + state_key, + timestamp, + content, + ) in events: + if state_key is not None: + state_info = (room_id, event_type, state_key) + if state_info in sent_state: + continue + else: + state_info = None try: - await self._send_event(*args) + await self._send_event( + user_localpart, + room_id, + event_type, + state_key, + timestamp, + content, + ) + if state_info is not None: + sent_state.add(state_info) except Exception: logger.exception("Failed to send delayed event on startup") + sent_state.clear() for delay_id, user_localpart, relative_delay in remaining_timeout_delays: self._schedule(delay_id, user_localpart, relative_delay)