mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 00:44:52 +01:00
OP-3908 - 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.)
This commit is contained in:
parent
3e90759d58
commit
dfb79da41f
3 changed files with 27 additions and 5 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
from Qt import QtWidgets
|
||||
import collections
|
||||
|
||||
import pyblish.api
|
||||
|
||||
|
|
@ -38,9 +39,10 @@ class PhotoshopHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost):
|
|||
name = "photoshop"
|
||||
|
||||
def install(self):
|
||||
"""Install Photoshop-specific functionality of avalon-core.
|
||||
"""Install Photoshop-specific functionality needed for integration.
|
||||
|
||||
This function is called automatically on calling `api.install(photoshop)`.
|
||||
This function is called automatically on calling
|
||||
`api.install(photoshop)`.
|
||||
"""
|
||||
log.info("Installing OpenPype Photoshop...")
|
||||
pyblish.api.register_host("photoshop")
|
||||
|
|
@ -289,3 +291,21 @@ def containerise(
|
|||
stub.imprint(layer.id, data)
|
||||
|
||||
return layer
|
||||
|
||||
|
||||
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.photoshop.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]
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from openpype.pipeline import (
|
|||
)
|
||||
from openpype.lib import prepare_template_data
|
||||
from openpype.pipeline.create import SUBSET_NAME_ALLOWED_SYMBOLS
|
||||
from openpype.hosts.photoshop.api import PhotoshopHost
|
||||
from openpype.hosts.photoshop.api.pipeline import cache_and_get_instances
|
||||
|
||||
|
||||
class ImageCreator(Creator):
|
||||
|
|
@ -20,7 +20,7 @@ class ImageCreator(Creator):
|
|||
description = "Image creator"
|
||||
|
||||
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=='image'
|
||||
creator_id = (instance_data.get("creator_identifier") or
|
||||
instance_data.get("family"))
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ from openpype.pipeline import (
|
|||
CreatedInstance,
|
||||
legacy_io
|
||||
)
|
||||
from openpype.hosts.photoshop.api.pipeline import cache_and_get_instances
|
||||
|
||||
|
||||
class PSWorkfileCreator(AutoCreator):
|
||||
identifier = "workfile"
|
||||
|
|
@ -16,7 +18,7 @@ class PSWorkfileCreator(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"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue