From d136144a4e2c685dc33435b063f95c4722c85b69 Mon Sep 17 00:00:00 2001 From: pablo Date: Sat, 26 Dec 2020 20:25:56 +0100 Subject: [PATCH] Throttling checks are now lazy. --- core/throttling_utils.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/core/throttling_utils.py b/core/throttling_utils.py index ccdf8d6..5b02bf3 100644 --- a/core/throttling_utils.py +++ b/core/throttling_utils.py @@ -147,12 +147,9 @@ class ThrottleManager: :return: True if all rules passed positively, False otherwise """ - check_results = self._check_all_rules(**kwargs) + check_result = self._check_all_rules(**kwargs) - if not all(check_results): - return False - - return True + return check_result def add_rule( self, rule: BaseThrottlingRule, required_argument_names: List[str] = None @@ -172,12 +169,12 @@ class ThrottleManager: return self - def _check_all_rules(self, **kwargs) -> List[bool]: + def _check_all_rules(self, **kwargs) -> bool: """ - Executes all checks with the right arguments for each of them and + Executes checks (lazily) with the right arguments for each of them and collects results. :param kwargs: all passed arguments - :return: the result of each individual check + :return: True if all checks passed, False otherwise """ checks = [] @@ -187,6 +184,7 @@ class ThrottleManager: for argument_name in self._rules_and_required_arguments[rule.__class__] } checks.append(rule(**arguments_for_rule)) - continue + if checks[-1] == False: + return False - return checks + return True