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

Commit

Permalink
Remove unneeded ActionGenerator class. (#12691)
Browse files Browse the repository at this point in the history
It simply passes through to `BulkPushRuleEvaluator`, which can be
called directly instead.
  • Loading branch information
clokep authored May 11, 2022
1 parent 84facf7 commit a4c7591
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 60 deletions.
1 change: 1 addition & 0 deletions changelog.d/12691.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove an unneeded class in the push code.
4 changes: 2 additions & 2 deletions synapse/handlers/federation_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, hs: "HomeServer"):
self._event_creation_handler = hs.get_event_creation_handler()
self._event_auth_handler = hs.get_event_auth_handler()
self._message_handler = hs.get_message_handler()
self._action_generator = hs.get_action_generator()
self._bulk_push_rule_evaluator = hs.get_bulk_push_rule_evaluator()
self._state_resolution_handler = hs.get_state_resolution_handler()
# avoid a circular dependency by deferring execution here
self._get_room_member_handler = hs.get_room_member_handler
Expand Down Expand Up @@ -1913,7 +1913,7 @@ async def _run_push_actions_and_persist_event(
min_depth,
)
else:
await self._action_generator.handle_push_actions_for_event(
await self._bulk_push_rule_evaluator.action_for_event_by_user(
event, context
)

Expand Down
6 changes: 4 additions & 2 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def __init__(self, hs: "HomeServer"):
# This is to stop us from diverging history *too* much.
self.limiter = Linearizer(max_count=5, name="room_event_creation_limit")

self.action_generator = hs.get_action_generator()
self._bulk_push_rule_evaluator = hs.get_bulk_push_rule_evaluator()

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

try:
# If we're a worker we need to hit out to the master.
Expand Down
5 changes: 0 additions & 5 deletions synapse/push/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
+---------------------------------------------+
|
v
+-----------------+
| ActionGenerator |
+-----------------+
|
v
+-----------------------+ +---------------------------+
| BulkPushRuleEvaluator |---->| PushRuleEvaluatorForEvent |
+-----------------------+ +---------------------------+
Expand Down
48 changes: 0 additions & 48 deletions synapse/push/action_generator.py

This file was deleted.

7 changes: 7 additions & 0 deletions synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from synapse.util.caches import CacheMetric, register_cache
from synapse.util.caches.descriptors import lru_cache
from synapse.util.caches.lrucache import LruCache
from synapse.util.metrics import measure_func

from .push_rule_evaluator import PushRuleEvaluatorForEvent

Expand Down Expand Up @@ -105,6 +106,7 @@ class BulkPushRuleEvaluator:
def __init__(self, hs: "HomeServer"):
self.hs = hs
self.store = hs.get_datastores().main
self.clock = hs.get_clock()
self._event_auth_handler = hs.get_event_auth_handler()

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

return pl_event.content if pl_event else {}, sender_level

@measure_func("action_for_event_by_user")
async def action_for_event_by_user(
self, event: EventBase, context: EventContext
) -> None:
"""Given an event and context, evaluate the push rules, check if the message
should increment the unread count, and insert the results into the
event_push_actions_staging table.
"""
if event.internal_metadata.is_outlier():
# This can happen due to out of band memberships
return

count_as_unread = _should_count_as_unread(event, context)

rules_by_user = await self._get_rules_for_event(event, context)
Expand Down
6 changes: 3 additions & 3 deletions synapse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
from synapse.http.matrixfederationclient import MatrixFederationHttpClient
from synapse.module_api import ModuleApi
from synapse.notifier import Notifier
from synapse.push.action_generator import ActionGenerator
from synapse.push.bulk_push_rule_evaluator import BulkPushRuleEvaluator
from synapse.push.pusherpool import PusherPool
from synapse.replication.tcp.client import ReplicationDataHandler
from synapse.replication.tcp.external_cache import ExternalCache
Expand Down Expand Up @@ -644,8 +644,8 @@ def get_replication_command_handler(self) -> ReplicationCommandHandler:
return ReplicationCommandHandler(self)

@cache_in_self
def get_action_generator(self) -> ActionGenerator:
return ActionGenerator(self)
def get_bulk_push_rule_evaluator(self) -> BulkPushRuleEvaluator:
return BulkPushRuleEvaluator(self)

@cache_in_self
def get_user_directory_handler(self) -> UserDirectoryHandler:
Expand Down

0 comments on commit a4c7591

Please sign in to comment.