mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
Merge pull request #363 from BigRoy/enhancement/maya_validate_node_ids_database_optimize
Maya: Validate node ids in database, query folder ids once
This commit is contained in:
commit
25484012d7
1 changed files with 38 additions and 10 deletions
|
|
@ -37,27 +37,27 @@ class ValidateNodeIdsInDatabase(pyblish.api.InstancePlugin):
|
|||
invalid = self.get_invalid(instance)
|
||||
if invalid:
|
||||
raise PublishValidationError(
|
||||
("Found folder ids which are not related to "
|
||||
"current project in instance: `{}`").format(instance.name))
|
||||
"Found folder ids which are not related to "
|
||||
"current project in instance: `{}`".format(instance.name))
|
||||
|
||||
@classmethod
|
||||
def get_invalid(cls, instance):
|
||||
|
||||
invalid = []
|
||||
nodes = instance[:]
|
||||
if not nodes:
|
||||
return
|
||||
|
||||
# Get all id required nodes
|
||||
id_required_nodes = lib.get_id_required_nodes(referenced_nodes=True,
|
||||
nodes=instance[:])
|
||||
nodes=nodes)
|
||||
if not id_required_nodes:
|
||||
return []
|
||||
|
||||
# check ids against database ids
|
||||
project_name = instance.context.data["projectName"]
|
||||
folder_entities = ayon_api.get_folders(project_name, fields={"id"})
|
||||
folder_ids = {
|
||||
folder_entity["id"]
|
||||
for folder_entity in folder_entities
|
||||
}
|
||||
folder_ids = cls.get_project_folder_ids(context=instance.context)
|
||||
|
||||
# Get all asset IDs
|
||||
invalid = []
|
||||
for node in id_required_nodes:
|
||||
cb_id = lib.get_id(node)
|
||||
|
||||
|
|
@ -71,3 +71,31 @@ class ValidateNodeIdsInDatabase(pyblish.api.InstancePlugin):
|
|||
invalid.append(node)
|
||||
|
||||
return invalid
|
||||
|
||||
@classmethod
|
||||
def get_project_folder_ids(cls, context):
|
||||
"""Return all folder ids in the current project.
|
||||
|
||||
Arguments:
|
||||
context (pyblish.api.Context): The publish context.
|
||||
|
||||
Returns:
|
||||
set[str]: All folder ids in the current project.
|
||||
|
||||
"""
|
||||
# We query the database only for the first instance instead of
|
||||
# per instance by storing a cache in the context
|
||||
key = "__cache_project_folder_ids"
|
||||
if key in context.data:
|
||||
return context.data[key]
|
||||
|
||||
# check ids against database
|
||||
project_name = context.data["projectName"]
|
||||
folder_entities = ayon_api.get_folders(project_name, fields={"id"})
|
||||
folder_ids = {
|
||||
folder_entity["id"]
|
||||
for folder_entity in folder_entities
|
||||
}
|
||||
|
||||
context.data[key] = folder_ids
|
||||
return folder_ids
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue