From 36d154799679f921fc3b13eefe1011e4f49e7cc6 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Fri, 23 Dec 2022 13:46:04 -0600 Subject: [PATCH 1/7] Ignore events from ourself --- synapse/appservice/scheduler.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/synapse/appservice/scheduler.py b/synapse/appservice/scheduler.py index 7b562795a3f2..b1029d59daeb 100644 --- a/synapse/appservice/scheduler.py +++ b/synapse/appservice/scheduler.py @@ -98,6 +98,7 @@ class ApplicationServiceScheduler: """ def __init__(self, hs: "HomeServer"): + self._hs = hs self.clock = hs.get_clock() self.store = hs.get_datastores().main self.as_api = hs.get_application_service_api() @@ -138,6 +139,11 @@ def enqueue_for_appservice( to refresh the device lists of, or those that the application service need no longer track the device lists of. """ + + # Ignore events that come from our own users. We probably already know about + # them and sent them ourself. + events = [event for event in events if self._hs.is_mine_id(event.sender)] + # We purposefully allow this method to run with empty events/ephemeral # collections, so that callers do not need to check iterable size themselves. if ( From d1f258ff950d1bca0aa0ccb450d3be2591d16a1d Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Fri, 23 Dec 2022 13:50:10 -0600 Subject: [PATCH 2/7] Add dummy changelog --- changelog.d/14729.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/14729.misc diff --git a/changelog.d/14729.misc b/changelog.d/14729.misc new file mode 100644 index 000000000000..2a273f14fd71 --- /dev/null +++ b/changelog.d/14729.misc @@ -0,0 +1 @@ +Don't merge this. From 018396a8a4b4d8346017ea7da3db134f98405a2a Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Fri, 23 Dec 2022 13:50:51 -0600 Subject: [PATCH 3/7] Correct filtering --- synapse/appservice/scheduler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/appservice/scheduler.py b/synapse/appservice/scheduler.py index b1029d59daeb..7979647f227d 100644 --- a/synapse/appservice/scheduler.py +++ b/synapse/appservice/scheduler.py @@ -142,7 +142,7 @@ def enqueue_for_appservice( # Ignore events that come from our own users. We probably already know about # them and sent them ourself. - events = [event for event in events if self._hs.is_mine_id(event.sender)] + events = [event for event in events if not self._hs.is_mine_id(event.sender)] # We purposefully allow this method to run with empty events/ephemeral # collections, so that callers do not need to check iterable size themselves. From 0f2dda20b26ed1a9d6150cf0c0253f0d81464def Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Fri, 23 Dec 2022 14:00:54 -0600 Subject: [PATCH 4/7] Add more/better comments --- synapse/appservice/scheduler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/synapse/appservice/scheduler.py b/synapse/appservice/scheduler.py index 7979647f227d..8afdf0c9931e 100644 --- a/synapse/appservice/scheduler.py +++ b/synapse/appservice/scheduler.py @@ -140,6 +140,9 @@ def enqueue_for_appservice( longer track the device lists of. """ + # XXX: Special patch just for Gitter which we should remove after the import, + # https://github.com/matrix-org/synapse/pull/14729 + # # Ignore events that come from our own users. We probably already know about # them and sent them ourself. events = [event for event in events if not self._hs.is_mine_id(event.sender)] From ea0489ba13704a0aef5fd8ce785ff144b9bad01c Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Fri, 23 Dec 2022 14:20:06 -0600 Subject: [PATCH 5/7] Move to after we know not None --- synapse/appservice/scheduler.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/synapse/appservice/scheduler.py b/synapse/appservice/scheduler.py index 8afdf0c9931e..8d17f7b77741 100644 --- a/synapse/appservice/scheduler.py +++ b/synapse/appservice/scheduler.py @@ -139,14 +139,6 @@ def enqueue_for_appservice( to refresh the device lists of, or those that the application service need no longer track the device lists of. """ - - # XXX: Special patch just for Gitter which we should remove after the import, - # https://github.com/matrix-org/synapse/pull/14729 - # - # Ignore events that come from our own users. We probably already know about - # them and sent them ourself. - events = [event for event in events if not self._hs.is_mine_id(event.sender)] - # We purposefully allow this method to run with empty events/ephemeral # collections, so that callers do not need to check iterable size themselves. if ( @@ -157,6 +149,13 @@ def enqueue_for_appservice( ): return + # XXX: Special patch just for Gitter which we should remove after the import, + # https://github.com/matrix-org/synapse/pull/14729 + # + # Ignore events that come from our own users. We probably already know about + # them and sent them ourself. + events = [event for event in events if not self._hs.is_mine_id(event.sender)] + if events: self.queuer.queued_events.setdefault(appservice.id, []).extend(events) if ephemeral: From fa8e029bfc4671144afdcd6d3745f361d9b769ed Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Fri, 23 Dec 2022 14:47:16 -0600 Subject: [PATCH 6/7] move it again --- synapse/appservice/scheduler.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/synapse/appservice/scheduler.py b/synapse/appservice/scheduler.py index 8d17f7b77741..d90d45b643ca 100644 --- a/synapse/appservice/scheduler.py +++ b/synapse/appservice/scheduler.py @@ -149,14 +149,16 @@ def enqueue_for_appservice( ): return - # XXX: Special patch just for Gitter which we should remove after the import, - # https://github.com/matrix-org/synapse/pull/14729 - # - # Ignore events that come from our own users. We probably already know about - # them and sent them ourself. - events = [event for event in events if not self._hs.is_mine_id(event.sender)] - if events: + # XXX: Special patch just for Gitter which we should remove after the import, + # https://github.com/matrix-org/synapse/pull/14729 + # + # Ignore events that come from our own users. We probably already know about + # them and sent them ourself. + events = [ + event for event in events if not self._hs.is_mine_id(event.sender) + ] + self.queuer.queued_events.setdefault(appservice.id, []).extend(events) if ephemeral: self.queuer.queued_ephemeral.setdefault(appservice.id, []).extend(ephemeral) From 13f6c6d115f6ff7e4210b316205d2beb9b485eae Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Sat, 24 Dec 2022 02:44:39 -0600 Subject: [PATCH 7/7] Protect both times --- synapse/appservice/scheduler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/synapse/appservice/scheduler.py b/synapse/appservice/scheduler.py index d90d45b643ca..ac8684407b34 100644 --- a/synapse/appservice/scheduler.py +++ b/synapse/appservice/scheduler.py @@ -159,6 +159,7 @@ def enqueue_for_appservice( event for event in events if not self._hs.is_mine_id(event.sender) ] + if events: self.queuer.queued_events.setdefault(appservice.id, []).extend(events) if ephemeral: self.queuer.queued_ephemeral.setdefault(appservice.id, []).extend(ephemeral)