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

Commit a4c7591

Browse files
authored
Remove unneeded ActionGenerator class. (#12691)
It simply passes through to `BulkPushRuleEvaluator`, which can be called directly instead.
1 parent 84facf7 commit a4c7591

7 files changed

Lines changed: 17 additions & 60 deletions

File tree

changelog.d/12691.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove an unneeded class in the push code.

synapse/handlers/federation_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __init__(self, hs: "HomeServer"):
103103
self._event_creation_handler = hs.get_event_creation_handler()
104104
self._event_auth_handler = hs.get_event_auth_handler()
105105
self._message_handler = hs.get_message_handler()
106-
self._action_generator = hs.get_action_generator()
106+
self._bulk_push_rule_evaluator = hs.get_bulk_push_rule_evaluator()
107107
self._state_resolution_handler = hs.get_state_resolution_handler()
108108
# avoid a circular dependency by deferring execution here
109109
self._get_room_member_handler = hs.get_room_member_handler
@@ -1913,7 +1913,7 @@ async def _run_push_actions_and_persist_event(
19131913
min_depth,
19141914
)
19151915
else:
1916-
await self._action_generator.handle_push_actions_for_event(
1916+
await self._bulk_push_rule_evaluator.action_for_event_by_user(
19171917
event, context
19181918
)
19191919

synapse/handlers/message.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def __init__(self, hs: "HomeServer"):
426426
# This is to stop us from diverging history *too* much.
427427
self.limiter = Linearizer(max_count=5, name="room_event_creation_limit")
428428

429-
self.action_generator = hs.get_action_generator()
429+
self._bulk_push_rule_evaluator = hs.get_bulk_push_rule_evaluator()
430430

431431
self.spam_checker = hs.get_spam_checker()
432432
self.third_party_event_rules: "ThirdPartyEventRules" = (
@@ -1249,7 +1249,9 @@ async def _persist_event(
12491249
# and `state_groups` because they have `prev_events` that aren't persisted yet
12501250
# (historical messages persisted in reverse-chronological order).
12511251
if not event.internal_metadata.is_historical():
1252-
await self.action_generator.handle_push_actions_for_event(event, context)
1252+
await self._bulk_push_rule_evaluator.action_for_event_by_user(
1253+
event, context
1254+
)
12531255

12541256
try:
12551257
# If we're a worker we need to hit out to the master.

synapse/push/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@
4343
+---------------------------------------------+
4444
|
4545
v
46-
+-----------------+
47-
| ActionGenerator |
48-
+-----------------+
49-
|
50-
v
5146
+-----------------------+ +---------------------------+
5247
| BulkPushRuleEvaluator |---->| PushRuleEvaluatorForEvent |
5348
+-----------------------+ +---------------------------+

synapse/push/action_generator.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

synapse/push/bulk_push_rule_evaluator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from synapse.util.caches import CacheMetric, register_cache
3030
from synapse.util.caches.descriptors import lru_cache
3131
from synapse.util.caches.lrucache import LruCache
32+
from synapse.util.metrics import measure_func
3233

3334
from .push_rule_evaluator import PushRuleEvaluatorForEvent
3435

@@ -105,6 +106,7 @@ class BulkPushRuleEvaluator:
105106
def __init__(self, hs: "HomeServer"):
106107
self.hs = hs
107108
self.store = hs.get_datastores().main
109+
self.clock = hs.get_clock()
108110
self._event_auth_handler = hs.get_event_auth_handler()
109111

110112
# Used by `RulesForRoom` to ensure only one thing mutates the cache at a
@@ -185,13 +187,18 @@ async def _get_power_levels_and_sender_level(
185187

186188
return pl_event.content if pl_event else {}, sender_level
187189

190+
@measure_func("action_for_event_by_user")
188191
async def action_for_event_by_user(
189192
self, event: EventBase, context: EventContext
190193
) -> None:
191194
"""Given an event and context, evaluate the push rules, check if the message
192195
should increment the unread count, and insert the results into the
193196
event_push_actions_staging table.
194197
"""
198+
if event.internal_metadata.is_outlier():
199+
# This can happen due to out of band memberships
200+
return
201+
195202
count_as_unread = _should_count_as_unread(event, context)
196203

197204
rules_by_user = await self._get_rules_for_event(event, context)

synapse/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
from synapse.http.matrixfederationclient import MatrixFederationHttpClient
120120
from synapse.module_api import ModuleApi
121121
from synapse.notifier import Notifier
122-
from synapse.push.action_generator import ActionGenerator
122+
from synapse.push.bulk_push_rule_evaluator import BulkPushRuleEvaluator
123123
from synapse.push.pusherpool import PusherPool
124124
from synapse.replication.tcp.client import ReplicationDataHandler
125125
from synapse.replication.tcp.external_cache import ExternalCache
@@ -644,8 +644,8 @@ def get_replication_command_handler(self) -> ReplicationCommandHandler:
644644
return ReplicationCommandHandler(self)
645645

646646
@cache_in_self
647-
def get_action_generator(self) -> ActionGenerator:
648-
return ActionGenerator(self)
647+
def get_bulk_push_rule_evaluator(self) -> BulkPushRuleEvaluator:
648+
return BulkPushRuleEvaluator(self)
649649

650650
@cache_in_self
651651
def get_user_directory_handler(self) -> UserDirectoryHandler:

0 commit comments

Comments
 (0)