From f78bd11977388c4f97de147bfadaba809cacb3c7 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Thu, 3 Nov 2022 10:26:53 +0100 Subject: [PATCH] OP-3909 - added caching of list_instances list_instances could be expensive in larger workfiles, it makes sense to cache it for all creator, but only for collecting phase. (This is why creator.collection_shared_data is used.) --- openpype/hosts/aftereffects/api/pipeline.py | 19 ++++++++++++++++++- .../plugins/create/create_render.py | 4 ++-- .../plugins/create/workfile_creator.py | 3 ++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/openpype/hosts/aftereffects/api/pipeline.py b/openpype/hosts/aftereffects/api/pipeline.py index 3babe404ed..cf5bcf242e 100644 --- a/openpype/hosts/aftereffects/api/pipeline.py +++ b/openpype/hosts/aftereffects/api/pipeline.py @@ -1,5 +1,5 @@ import os - +import collections from Qt import QtWidgets import pyblish.api @@ -292,3 +292,20 @@ def containerise(name, return comp + +def cache_and_get_instances(creator): + """Cache instances in shared data. + Args: + creator (Creator): Plugin which would like to get instances from host. + Returns: + Dict[str, Dict[str, Any]]: Cached instances list from host + implementation. + """ + shared_key = "openpype.aftereffects.instances" + if shared_key not in creator.collection_shared_data: + value = collections.defaultdict(list) + for instance in creator.list_instances(): + identifier = instance["creator_identifier"] + value[identifier].append(instance) + creator.collection_shared_data[shared_key] = value + return creator.collection_shared_data[shared_key] diff --git a/openpype/hosts/aftereffects/plugins/create/create_render.py b/openpype/hosts/aftereffects/plugins/create/create_render.py index f6c95d0699..01d59abb37 100644 --- a/openpype/hosts/aftereffects/plugins/create/create_render.py +++ b/openpype/hosts/aftereffects/plugins/create/create_render.py @@ -7,7 +7,7 @@ from openpype.pipeline import ( CreatorError, legacy_io, ) - +from openpype.hosts.aftereffects.api.pipeline import cache_and_get_instances class RenderCreator(Creator): identifier = "render" @@ -28,7 +28,7 @@ class RenderCreator(Creator): return resources.get_openpype_splash_filepath() def collect_instances(self): - for instance_data in self.host.list_instances(): + for instance_data in cache_and_get_instances(self): # legacy instances have family=='render' or 'renderLocal', use them creator_id = (instance_data.get("creator_identifier") or instance_data.get("family", '').replace("Local", '')) diff --git a/openpype/hosts/aftereffects/plugins/create/workfile_creator.py b/openpype/hosts/aftereffects/plugins/create/workfile_creator.py index 447b8cf72b..c698af896b 100644 --- a/openpype/hosts/aftereffects/plugins/create/workfile_creator.py +++ b/openpype/hosts/aftereffects/plugins/create/workfile_creator.py @@ -5,6 +5,7 @@ from openpype.pipeline import ( CreatedInstance, legacy_io, ) +from openpype.hosts.aftereffects.api.pipeline import cache_and_get_instances class AEWorkfileCreator(AutoCreator): @@ -17,7 +18,7 @@ class AEWorkfileCreator(AutoCreator): return [] def collect_instances(self): - for instance_data in self.host.list_instances(): + for instance_data in cache_and_get_instances(self): creator_id = instance_data.get("creator_identifier") if creator_id == self.identifier: subset_name = instance_data["subset"]