Address minor PR issues
This commit is contained in:
parent
d2a92c6bde
commit
3051c9d002
|
@ -267,8 +267,8 @@ class BaseHandler(object):
|
|||
event, context=context
|
||||
)
|
||||
|
||||
action_generator = ActionGenerator(self.hs, self.store)
|
||||
yield action_generator.handle_event(serialize_event(
|
||||
action_generator = ActionGenerator(self.store)
|
||||
yield action_generator.handle_push_actions_for_event(serialize_event(
|
||||
event, self.clock.time_msec()
|
||||
))
|
||||
|
||||
|
|
|
@ -245,8 +245,8 @@ class FederationHandler(BaseHandler):
|
|||
yield user_joined_room(self.distributor, user, event.room_id)
|
||||
|
||||
if not backfilled and not event.internal_metadata.is_outlier():
|
||||
action_generator = ActionGenerator(self.hs, self.store)
|
||||
yield action_generator.handle_event(serialize_event(
|
||||
action_generator = ActionGenerator(self.store)
|
||||
yield action_generator.handle_push_actions_for_event(serialize_event(
|
||||
event, self.clock.time_msec())
|
||||
)
|
||||
|
||||
|
|
|
@ -23,8 +23,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class ActionGenerator:
|
||||
def __init__(self, hs, store):
|
||||
self.hs = hs
|
||||
def __init__(self, store):
|
||||
self.store = store
|
||||
# really we want to get all user ids and all profile tags too,
|
||||
# since we want the actions for each profile tag for every user and
|
||||
|
@ -34,9 +33,9 @@ class ActionGenerator:
|
|||
# tag (ie. we just need all the users).
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def handle_event(self, event):
|
||||
def handle_push_actions_for_event(self, event):
|
||||
bulk_evaluator = yield bulk_push_rule_evaluator.evaluator_for_room_id(
|
||||
event['room_id'], self.hs, self.store
|
||||
event['room_id'], self.store
|
||||
)
|
||||
|
||||
actions_by_user = bulk_evaluator.action_for_event_by_user(event)
|
||||
|
|
|
@ -33,7 +33,7 @@ def decode_rule_json(rule):
|
|||
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def evaluator_for_room_id(room_id, hs, store):
|
||||
def evaluator_for_room_id(room_id, store):
|
||||
users = yield store.get_users_in_room(room_id)
|
||||
rules_by_user = yield store.bulk_get_push_rules(users)
|
||||
rules_by_user = {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2014 OpenMarket Ltd
|
||||
# Copyright 2015 OpenMarket Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -62,12 +62,12 @@ class PushRuleStore(SQLBaseStore):
|
|||
def f(txn, user_ids_to_fetch):
|
||||
sql = (
|
||||
"SELECT " +
|
||||
",".join(map(lambda x: "pr."+x, PushRuleTable.fields)) +
|
||||
",".join("pr."+x for x in PushRuleTable.fields) +
|
||||
" FROM " + PushRuleTable.table_name + " pr " +
|
||||
" LEFT JOIN " + PushRuleEnableTable.table_name + " pre " +
|
||||
" ON pr.user_name = pre.user_name and pr.rule_id = pre.rule_id " +
|
||||
" WHERE pr.user_name " +
|
||||
" IN (" + ",".join(["?" for _ in user_ids_to_fetch]) + ")"
|
||||
" IN (" + ",".join("?" for _ in user_ids_to_fetch) + ")"
|
||||
" AND (pre.enabled is null or pre.enabled = 1)"
|
||||
" ORDER BY pr.user_name, pr.priority_class DESC, pr.priority DESC"
|
||||
)
|
||||
|
@ -78,7 +78,7 @@ class PushRuleStore(SQLBaseStore):
|
|||
|
||||
batch_start = 0
|
||||
while batch_start < len(user_ids):
|
||||
batch_end = max(len(user_ids), batch_size)
|
||||
batch_end = min(len(user_ids), batch_size)
|
||||
batch_user_ids = user_ids[batch_start:batch_end]
|
||||
batch_start = batch_end
|
||||
|
||||
|
|
|
@ -291,18 +291,6 @@ class RegistrationStore(SQLBaseStore):
|
|||
defer.returnValue(ret['user_id'])
|
||||
defer.returnValue(None)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_all_user_ids(self):
|
||||
"""Returns all user ids registered on this homeserver"""
|
||||
return self.runInteraction(
|
||||
"get_all_user_ids",
|
||||
self._get_all_user_ids_txn
|
||||
)
|
||||
|
||||
def _get_all_user_ids_txn(self, txn):
|
||||
txn.execute("SELECT name from users")
|
||||
return [r[0] for r in txn.fetchall()]
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def count_all_users(self):
|
||||
"""Counts all users registered on the homeserver."""
|
||||
|
|
Loading…
Reference in New Issue