Skip to content
This repository was archived by the owner on Oct 10, 2024. It is now read-only.

Commit cf3bf2d

Browse files
authored
Merge pull request #68 from pypeclub/feature/PYPE-502_gui_open_too_long
feature/PYPE-502_gui_open_too_long
2 parents 1a3157f + 1662e67 commit cf3bf2d

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

avalon/tools/gui/models/model_asset.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,28 @@ def __init__(self, parent=None):
3131
super(AssetModel, self).__init__(parent=parent)
3232
self.refresh()
3333

34-
def _add_hierarchy(self, parent=None):
34+
def _add_hierarchy(self, parent=None, assets={}):
3535

3636
# Find the assets under the parent
37-
find_data = {
38-
"type": "asset"
39-
}
37+
current_assets = []
4038
if parent is None:
41-
find_data['$or'] = [
42-
{'data.visualParent': {'$exists': False}},
43-
{'data.visualParent': None}
44-
]
39+
db_assets = io.find({
40+
"type": "asset"
41+
}).sort('name', 1)
42+
assets = {}
43+
for asset in db_assets:
44+
parent_id = asset.get("data", {}).get("visualParent")
45+
if parent_id:
46+
if parent_id not in assets:
47+
assets[parent_id] = []
48+
assets[parent_id].append(asset)
49+
else:
50+
current_assets.append(asset)
4551
else:
46-
find_data["data.visualParent"] = parent['_id']
52+
if parent["_id"] in assets:
53+
current_assets = assets.pop(parent["_id"])
4754

48-
assets = io.find(find_data).sort('name', 1)
49-
for asset in assets:
55+
for asset in current_assets:
5056
# get label from data, otherwise use name
5157
data = asset.get("data", {})
5258
label = data.get("label", asset['name'])
@@ -67,7 +73,10 @@ def _add_hierarchy(self, parent=None):
6773
self.add_child(node, parent=parent)
6874

6975
# Add asset's children recursively
70-
self._add_hierarchy(node)
76+
if asset['_id'] in assets:
77+
assets = self._add_hierarchy(node, assets)
78+
79+
return assets
7180

7281
def refresh(self):
7382
"""Refresh the data for the model."""

0 commit comments

Comments
 (0)