mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-05 04:15:03 -04:00
Move free functions into PushRuleEvaluatorForEvent. (#12677)
* Move `_condition_checker` into `PushRuleEvaluatorForEvent`. * Move the condition cache into `PushRuleEvaluatorForEvent`. * Improve docstrings. * Inline a method which is only called once.
This commit is contained in:
parent
02cdace707
commit
b44fbdffa4
3 changed files with 69 additions and 34 deletions
|
@ -208,8 +208,6 @@ class BulkPushRuleEvaluator:
|
|||
event, len(room_members), sender_power_level, power_levels
|
||||
)
|
||||
|
||||
condition_cache: Dict[str, bool] = {}
|
||||
|
||||
# If the event is not a state event check if any users ignore the sender.
|
||||
if not event.is_state():
|
||||
ignorers = await self.store.ignored_by(event.sender)
|
||||
|
@ -247,8 +245,8 @@ class BulkPushRuleEvaluator:
|
|||
if "enabled" in rule and not rule["enabled"]:
|
||||
continue
|
||||
|
||||
matches = _condition_checker(
|
||||
evaluator, rule["conditions"], uid, display_name, condition_cache
|
||||
matches = evaluator.check_conditions(
|
||||
rule["conditions"], uid, display_name
|
||||
)
|
||||
if matches:
|
||||
actions = [x for x in rule["actions"] if x != "dont_notify"]
|
||||
|
@ -267,32 +265,6 @@ class BulkPushRuleEvaluator:
|
|||
)
|
||||
|
||||
|
||||
def _condition_checker(
|
||||
evaluator: PushRuleEvaluatorForEvent,
|
||||
conditions: List[dict],
|
||||
uid: str,
|
||||
display_name: Optional[str],
|
||||
cache: Dict[str, bool],
|
||||
) -> bool:
|
||||
for cond in conditions:
|
||||
_cache_key = cond.get("_cache_key", None)
|
||||
if _cache_key:
|
||||
res = cache.get(_cache_key, None)
|
||||
if res is False:
|
||||
return False
|
||||
elif res is True:
|
||||
continue
|
||||
|
||||
res = evaluator.matches(cond, uid, display_name)
|
||||
if _cache_key:
|
||||
cache[_cache_key] = bool(res)
|
||||
|
||||
if not res:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
MemberMap = Dict[str, Optional[EventIdMembership]]
|
||||
Rule = Dict[str, dict]
|
||||
RulesByUser = Dict[str, List[Rule]]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue