Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3376 from pypeclub/feature/OP-3379_Use-query-func…
Browse files Browse the repository at this point in the history
…tions-in-Celaction
  • Loading branch information
mkolar authored Jun 24, 2022
2 parents d531aa2 + d3afa47 commit 6c12c50
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions openpype/hosts/celaction/plugins/publish/collect_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

import pyblish.api

from openpype.client import (
get_subsets,
get_last_versions,
get_representations
)
from openpype.pipeline import legacy_io


Expand Down Expand Up @@ -60,10 +65,10 @@ def get_subsets(self, asset_doc, representations):
"""

# Query all subsets for asset
subset_docs = legacy_io.find({
"type": "subset",
"parent": asset_doc["_id"]
})
project_name = legacy_io.active_project()
subset_docs = get_subsets(
project_name, asset_ids=[asset_doc["_id"]], fields=["_id"]
)
# Collect all subset ids
subset_ids = [
subset_doc["_id"]
Expand All @@ -76,37 +81,19 @@ def get_subsets(self, asset_doc, representations):
"Try this for start `r'.*'`: asset: `{}`"
).format(asset_doc["name"])

# Last version aggregation
pipeline = [
# Find all versions of those subsets
{"$match": {
"type": "version",
"parent": {"$in": subset_ids}
}},
# Sorting versions all together
{"$sort": {"name": 1}},
# Group them by "parent", but only take the last
{"$group": {
"_id": "$parent",
"_version_id": {"$last": "$_id"},
"name": {"$last": "$name"}
}}
]
last_versions_by_subset_id = dict()
for doc in legacy_io.aggregate(pipeline):
doc["parent"] = doc["_id"]
doc["_id"] = doc.pop("_version_id")
last_versions_by_subset_id[doc["parent"]] = doc
last_versions_by_subset_id = get_last_versions(
project_name, subset_ids, fields=["_id", "parent"]
)

version_docs_by_id = {}
for version_doc in last_versions_by_subset_id.values():
version_docs_by_id[version_doc["_id"]] = version_doc

repre_docs = legacy_io.find({
"type": "representation",
"parent": {"$in": list(version_docs_by_id.keys())},
"name": {"$in": representations}
})
repre_docs = get_representations(
project_name,
version_ids=version_docs_by_id.keys(),
representation_names=representations
)
repre_docs_by_version_id = collections.defaultdict(list)
for repre_doc in repre_docs:
version_id = repre_doc["parent"]
Expand Down

0 comments on commit 6c12c50

Please sign in to comment.