Throttling checks are now lazy.
This commit is contained in:
parent
2a9483981e
commit
d136144a4e
1 changed files with 8 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue