From dd02631786628729fec3fcb696696d1761d513bb Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 3 Jun 2024 17:46:01 +0200 Subject: [PATCH] AY-5539 - do only single re compile re.compile might be expensive, do it outside of loop --- client/ayon_core/tools/publisher/control.py | 24 +++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 66487343d1..f2a440d701 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1856,9 +1856,13 @@ class PublisherController(BasePublisherController): return output def _get_allowed_creator_labels(self): - """Provide configured creator label in this context + """Provide configured creator labels in this context - If no profile matches current context, it shows all creators + If no profile matches current context, it shows all creators. + Support usage of regular expressions for configured values. + Returns: + (str): None or regex compiled patterns into single one + ('Render|Image.*') """ task_type = self._create_context.get_current_task_type() @@ -1890,14 +1894,20 @@ class PublisherController(BasePublisherController): if label } self.log.debug(f"Only allowed `{allowed_creator_labels}` creators") + allowed_creator_labels = ( + re.compile("|".join(allowed_creator_labels))) return allowed_creator_labels - def _is_label_allowed(self, label, allowed_labels): - """Implement regex support for allowed labels.""" - if not allowed_labels: + def _is_label_allowed(self, label, allowed_label_regexes): + """Implement regex support for allowed labels. + + Args: + label (str): Label of creator - shown in Publisher + allowed_label_regexes (str): compiled regular expression + """ + if not allowed_label_regexes: return True - allowed_patterns = re.compile("|".join(allowed_labels)) - return bool(allowed_patterns.match(label)) + return bool(allowed_label_regexes.match(label)) def _reset_instances(self): """Reset create instances."""