Skip to content

Commit

Permalink
Fix filtering skip_patterns (#868)
Browse files Browse the repository at this point in the history
* Fix filtering skip_patterns

* cache skip actions
  • Loading branch information
Tishka17 committed Aug 13, 2022
1 parent 016a8d3 commit d565406
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion aiogram/dispatcher/middlewares.py
Expand Up @@ -110,6 +110,19 @@ class LifetimeControllerMiddleware(BaseMiddleware):
# TODO: Rename class

skip_patterns = None
_skip_actions = None

@property
def skip_actions(self):
if self._skip_actions is None:
self._skip_actions = []
if self.skip_patterns:
self._skip_actions.extend([
f"pre_process_{item}",
f"process_{item}",
f"post_process_{item}",
])
return self._skip_actions

async def pre_process(self, obj, data, *args):
pass
Expand All @@ -118,7 +131,7 @@ async def post_process(self, obj, data, *args):
pass

async def trigger(self, action, args):
if self.skip_patterns is not None and any(item in action for item in self.skip_patterns):
if action in self.skip_actions:
return False

obj, *args, data = args
Expand Down

0 comments on commit d565406

Please sign in to comment.