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

Remove unneeded ActionGenerator class. #12691

Merged
merged 3 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +198 to +200
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erikjohnston are we OK with this moving into the measured function? It was added in #12689.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fine!


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