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

Commit

Permalink
Merge branch 'develop' of github.com:matrix-org/synapse into matrix-o…
Browse files Browse the repository at this point in the history
…rg-hotfixes
  • Loading branch information
erikjohnston committed May 19, 2017
2 parents 5b83e95 + 99713dc commit 3da4263
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
5 changes: 2 additions & 3 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

from synapse.util.retryutils import NotRetryingDestination

from synapse.push.action_generator import ActionGenerator
from synapse.util.distributor import user_joined_room

from twisted.internet import defer
Expand Down Expand Up @@ -75,6 +74,7 @@ def __init__(self, hs):
self.state_handler = hs.get_state_handler()
self.server_name = hs.hostname
self.keyring = hs.get_keyring()
self.action_generator = hs.get_action_generator()

self.replication_layer.set_handler(self)

Expand Down Expand Up @@ -1389,8 +1389,7 @@ def _handle_new_event(self, origin, event, state=None, auth_events=None,
)

if not event.internal_metadata.is_outlier():
action_generator = ActionGenerator(self.hs)
yield action_generator.handle_push_actions_for_event(
yield self.action_generator.handle_push_actions_for_event(
event, context
)

Expand Down
3 changes: 1 addition & 2 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from synapse.crypto.event_signing import add_hashes_and_signatures
from synapse.events.utils import serialize_event
from synapse.events.validator import EventValidator
from synapse.push.action_generator import ActionGenerator
from synapse.types import (
UserID, RoomAlias, RoomStreamToken,
)
Expand Down Expand Up @@ -54,7 +53,7 @@ def __init__(self, hs):
# This is to stop us from diverging history *too* much.
self.limiter = Limiter(max_count=5)

self.action_generator = ActionGenerator(self.hs)
self.action_generator = hs.get_action_generator()

@defer.inlineCallbacks
def purge_history(self, room_id, event_id):
Expand Down
2 changes: 1 addition & 1 deletion synapse/push/action_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
logger = logging.getLogger(__name__)


class ActionGenerator:
class ActionGenerator(object):
def __init__(self, hs):
self.hs = hs
self.clock = hs.get_clock()
Expand Down
23 changes: 16 additions & 7 deletions synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
from synapse.util.caches.descriptors import cached
from synapse.util.async import Linearizer

from collections import namedtuple


logger = logging.getLogger(__name__)


rules_by_room = {}


class BulkPushRuleEvaluator:
class BulkPushRuleEvaluator(object):
"""Calculates the outcome of push rules for an event for all users in the
room at once.
"""
Expand Down Expand Up @@ -204,12 +206,7 @@ def __init__(self, hs, room_id, rules_for_room_cache):
# To get around this we pass a function that on invalidations looks ups
# the RoomsForUser entry in the cache, rather than keeping a reference
# to self around in the callback.
def invalidate_all_cb():
rules = rules_for_room_cache.get(room_id, update_metrics=False)
if rules:
rules.invalidate_all()

self.invalidate_all_cb = invalidate_all_cb
self.invalidate_all_cb = _Invalidation(rules_for_room_cache, room_id)

@defer.inlineCallbacks
def get_rules(self, context):
Expand Down Expand Up @@ -347,3 +344,15 @@ def update_cache(self, sequence, members, rules_by_user, state_group):
self.member_map.update(members)
self.rules_by_user = rules_by_user
self.state_group = state_group


class _Invalidation(namedtuple("_Invalidation", ("cache", "room_id"))):
# We rely on _CacheContext implementing __eq__ and __hash__ sensibly,
# which namedtuple does for us (i.e. two _CacheContext are the same if
# their caches and keys match). This is important in particular to
# dedupe when we add callbacks to lru cache nodes, otherwise the number
# of callbacks would grow.
def __call__(self):
rules = self.cache.get(self.room_id, None, update_metrics=False)
if rules:
rules.invalidate_all()
5 changes: 5 additions & 0 deletions synapse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from synapse.http.client import SimpleHttpClient, InsecureInterceptableContextFactory
from synapse.http.matrixfederationclient import MatrixFederationHttpClient
from synapse.notifier import Notifier
from synapse.push.action_generator import ActionGenerator
from synapse.push.pusherpool import PusherPool
from synapse.rest.media.v1.media_repository import MediaRepository
from synapse.state import StateHandler
Expand Down Expand Up @@ -135,6 +136,7 @@ def build_DEPENDENCY(self)
'macaroon_generator',
'tcp_replication',
'read_marker_handler',
'action_generator',
]

def __init__(self, hostname, **kwargs):
Expand Down Expand Up @@ -299,6 +301,9 @@ def build_read_marker_handler(self):
def build_tcp_replication(self):
raise NotImplementedError()

def build_action_generator(self):
return ActionGenerator(self)

def remove_pusher(self, app_id, push_key, user_id):
return self.get_pusherpool().remove_pusher(app_id, push_key, user_id)

Expand Down

0 comments on commit 3da4263

Please sign in to comment.