From d3afa478b71974fff455669a394eaff3bca3468e Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Mon, 20 Jun 2022 19:01:47 +0200 Subject: [PATCH] use query functions in celaction --- .../plugins/publish/collect_audio.py | 47 +++++++------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/openpype/hosts/celaction/plugins/publish/collect_audio.py b/openpype/hosts/celaction/plugins/publish/collect_audio.py index 8acda5fc7cc..c6e3bf2c03a 100644 --- a/openpype/hosts/celaction/plugins/publish/collect_audio.py +++ b/openpype/hosts/celaction/plugins/publish/collect_audio.py @@ -4,6 +4,11 @@ import pyblish.api +from openpype.client import ( + get_subsets, + get_last_versions, + get_representations +) from openpype.pipeline import legacy_io @@ -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"] @@ -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"]