mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
do not get the container item from self.get_container
This commit is contained in:
parent
dcb838e145
commit
735409f9ac
3 changed files with 48 additions and 54 deletions
|
|
@ -130,6 +130,7 @@ class InventoryModel(QtGui.QStandardItemModel):
|
|||
self._clear_items()
|
||||
|
||||
items_by_repre_id = {}
|
||||
project_names = set()
|
||||
for container_item in container_items:
|
||||
# if (
|
||||
# selected is not None
|
||||
|
|
@ -137,8 +138,10 @@ class InventoryModel(QtGui.QStandardItemModel):
|
|||
# ):
|
||||
# continue
|
||||
repre_id = container_item.representation_id
|
||||
project_name = container_item.project_name
|
||||
items = items_by_repre_id.setdefault(repre_id, [])
|
||||
items.append(container_item)
|
||||
project_names.add(project_name)
|
||||
|
||||
repre_id = set(items_by_repre_id.keys())
|
||||
repre_info_by_id = self._controller.get_representation_info_items(
|
||||
|
|
@ -150,7 +153,7 @@ class InventoryModel(QtGui.QStandardItemModel):
|
|||
if repre_info.is_valid
|
||||
}
|
||||
version_items_by_product_id = self._controller.get_version_items(
|
||||
product_ids, repre_id
|
||||
product_ids, project_names
|
||||
)
|
||||
# SiteSync addon information
|
||||
progress_by_id = self._controller.get_representations_site_progress(
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ from ayon_api.graphql import GraphQlQuery
|
|||
|
||||
from ayon_core.host import ILoadHost
|
||||
from ayon_core.tools.common_models.projects import StatusStates
|
||||
from ayon_core.pipeline.context_tools import get_current_project_name
|
||||
|
||||
|
||||
# --- Implementation that should be in ayon-python-api ---
|
||||
|
|
@ -112,8 +111,7 @@ class ContainerItem:
|
|||
namespace=container["namespace"],
|
||||
object_name=container["objectName"],
|
||||
item_id=uuid.uuid4().hex,
|
||||
project_name=container.get(
|
||||
"project_name", get_current_project_name())
|
||||
project_name=container.get("project_name", None)
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -194,15 +192,21 @@ class ContainersModel:
|
|||
self._items_cache = None
|
||||
self._containers_by_id = {}
|
||||
self._container_items_by_id = {}
|
||||
self._container_items_by_project = {}
|
||||
self._project_name_by_repre_id = {}
|
||||
self._version_items_by_product_id = {}
|
||||
self._repre_info_by_id = {}
|
||||
self._product_id_by_project = {}
|
||||
|
||||
def reset(self):
|
||||
self._items_cache = None
|
||||
self._containers_by_id = {}
|
||||
self._container_items_by_id = {}
|
||||
self._container_items_by_project = {}
|
||||
self._project_name_by_repre_id = {}
|
||||
self._version_items_by_product_id = {}
|
||||
self._repre_info_by_id = {}
|
||||
self._product_id_by_project = {}
|
||||
|
||||
def get_containers(self):
|
||||
self._update_cache()
|
||||
|
|
@ -226,10 +230,8 @@ class ContainersModel:
|
|||
|
||||
def get_representation_info_items(self, representation_ids):
|
||||
output = {}
|
||||
missing_repre_ids = set()
|
||||
missing_repre_ids_by_project = {}
|
||||
containers = self._controller.get_containers()
|
||||
|
||||
current_project_name = self._controller.get_current_project_name()
|
||||
for repre_id in representation_ids:
|
||||
try:
|
||||
uuid.UUID(repre_id)
|
||||
|
|
@ -237,23 +239,23 @@ class ContainersModel:
|
|||
output[repre_id] = RepresentationInfo.new_invalid()
|
||||
continue
|
||||
|
||||
project_name = self._find_project_name(containers, repre_id)
|
||||
project_name = self._project_name_by_repre_id.get(repre_id)
|
||||
if project_name is None:
|
||||
project_name = self._controller.get_current_project_name()
|
||||
|
||||
project_name = current_project_name
|
||||
repre_info = self._repre_info_by_id.get(repre_id)
|
||||
if repre_info is None:
|
||||
missing_repre_ids.add(repre_id)
|
||||
missing_repre_ids_by_project.update({project_name: repre_id})
|
||||
missing_repre_ids_by_project.setdefault(
|
||||
project_name, set()
|
||||
).add(repre_id)
|
||||
else:
|
||||
output[repre_id] = repre_info
|
||||
|
||||
if not missing_repre_ids:
|
||||
if not missing_repre_ids_by_project:
|
||||
return output
|
||||
|
||||
for project_name, missing_ids in missing_repre_ids_by_project.items():
|
||||
repre_hierarchy_by_id = get_representations_hierarchy(
|
||||
project_name, {missing_ids}
|
||||
project_name, missing_ids
|
||||
)
|
||||
for repre_id, repre_hierarchy in repre_hierarchy_by_id.items():
|
||||
kwargs = {
|
||||
|
|
@ -286,19 +288,23 @@ class ContainersModel:
|
|||
|
||||
repre_info = RepresentationInfo(**kwargs)
|
||||
self._repre_info_by_id[repre_id] = repre_info
|
||||
self._product_id_by_project[project_name] = repre_info.product_id
|
||||
output[repre_id] = repre_info
|
||||
return output
|
||||
|
||||
def get_version_items(self, product_ids, representation_ids):
|
||||
project_ids_by_project_names = {}
|
||||
def get_version_items(self, product_ids, project_names):
|
||||
if not product_ids:
|
||||
return {}
|
||||
|
||||
missing_ids = {
|
||||
product_id
|
||||
for product_id in product_ids
|
||||
if product_id not in self._version_items_by_product_id
|
||||
}
|
||||
|
||||
product_ids_by_project = {
|
||||
project_name: self._product_id_by_project.get(project_name)
|
||||
for project_name in project_names
|
||||
}
|
||||
if missing_ids:
|
||||
status_items_by_name = {
|
||||
status_item.name: status_item
|
||||
|
|
@ -307,34 +313,20 @@ class ContainersModel:
|
|||
|
||||
def version_sorted(entity):
|
||||
return entity["version"]
|
||||
containers = self.get_containers()
|
||||
for repre_id in representation_ids:
|
||||
project_name = self._find_project_name(containers, repre_id)
|
||||
if project_name is None:
|
||||
project_name = self._controller.get_current_project_name()
|
||||
repre_hierarchy_by_id = get_representations_hierarchy(
|
||||
project_name, {repre_id}
|
||||
)
|
||||
product_ids_list = set()
|
||||
for repre_hierarchy in repre_hierarchy_by_id.values():
|
||||
product = repre_hierarchy.product
|
||||
product_id = product["id"]
|
||||
if product_id not in missing_ids:
|
||||
continue
|
||||
product_ids_list.add(product_id)
|
||||
project_ids_by_project_names.update({project_name: product_ids_list})
|
||||
|
||||
version_entities_list = []
|
||||
version_entities_by_product_id = {
|
||||
product_id: []
|
||||
for product_id in missing_ids
|
||||
}
|
||||
version_entities_list = []
|
||||
for project_name, missing_product_ids in project_ids_by_project_names.items():
|
||||
for project_name, product_id in product_ids_by_project.items():
|
||||
if product_id not in missing_ids:
|
||||
continue
|
||||
version_entities = list(ayon_api.get_versions(
|
||||
project_name,
|
||||
product_ids=missing_product_ids,
|
||||
product_ids={product_id},
|
||||
fields={"id", "version", "productId", "status"}
|
||||
))
|
||||
|
||||
version_entities_list.extend(version_entities)
|
||||
version_entities_list.sort(key=version_sorted)
|
||||
for version_entity in version_entities_list:
|
||||
|
|
@ -342,7 +334,6 @@ class ContainersModel:
|
|||
version_entities_by_product_id[product_id].append(
|
||||
version_entity
|
||||
)
|
||||
|
||||
for product_id, version_entities in (
|
||||
version_entities_by_product_id.items()
|
||||
):
|
||||
|
|
@ -373,13 +364,6 @@ class ContainersModel:
|
|||
for product_id in product_ids
|
||||
}
|
||||
|
||||
def _find_project_name(self, containers, representation_id):
|
||||
# Function to find the project name by representation
|
||||
for container in containers:
|
||||
if container.get('representation') == representation_id:
|
||||
return container.get('project_name', get_current_project_name())
|
||||
return None
|
||||
|
||||
def _update_cache(self):
|
||||
if self._items_cache is not None:
|
||||
return
|
||||
|
|
@ -395,6 +379,7 @@ class ContainersModel:
|
|||
container_items = []
|
||||
containers_by_id = {}
|
||||
container_items_by_id = {}
|
||||
project_name_by_repre_id = {}
|
||||
invalid_ids_mapping = {}
|
||||
for container in containers:
|
||||
try:
|
||||
|
|
@ -418,8 +403,10 @@ class ContainersModel:
|
|||
|
||||
containers_by_id[item.item_id] = container
|
||||
container_items_by_id[item.item_id] = item
|
||||
project_name_by_repre_id[item.representation_id] = item.project_name
|
||||
container_items.append(item)
|
||||
|
||||
self._containers_by_id = containers_by_id
|
||||
self._container_items_by_id = container_items_by_id
|
||||
self._project_name_by_repre_id = project_name_by_repre_id
|
||||
self._items_cache = container_items
|
||||
|
|
|
|||
|
|
@ -208,6 +208,7 @@ class SceneInventoryView(QtWidgets.QTreeView):
|
|||
filtered_items = []
|
||||
product_ids = set()
|
||||
version_ids = set()
|
||||
project_names = set()
|
||||
for container_item in container_items_by_id.values():
|
||||
repre_id = container_item.representation_id
|
||||
repre_info = repre_info_by_id.get(repre_id)
|
||||
|
|
@ -215,6 +216,7 @@ class SceneInventoryView(QtWidgets.QTreeView):
|
|||
filtered_items.append(container_item)
|
||||
version_ids.add(repre_info.version_id)
|
||||
product_ids.add(repre_info.product_id)
|
||||
project_names.add(container_item.project_name)
|
||||
|
||||
# remove
|
||||
remove_icon = qtawesome.icon("fa.remove", color=DEFAULT_COLOR)
|
||||
|
|
@ -228,11 +230,7 @@ class SceneInventoryView(QtWidgets.QTreeView):
|
|||
return
|
||||
|
||||
version_items_by_product_id = self._controller.get_version_items(
|
||||
product_ids, {
|
||||
container_item.representation_id
|
||||
for container_item in container_items_by_id.values()
|
||||
}
|
||||
)
|
||||
product_ids, project_names)
|
||||
has_outdated = False
|
||||
has_loaded_hero_versions = False
|
||||
has_available_hero_version = False
|
||||
|
|
@ -742,6 +740,10 @@ class SceneInventoryView(QtWidgets.QTreeView):
|
|||
container_item.representation_id
|
||||
for container_item in container_items_by_id.values()
|
||||
}
|
||||
project_names = {
|
||||
container_item.project_name
|
||||
for container_item in container_items_by_id.values()
|
||||
}
|
||||
repre_info_by_id = self._controller.get_representation_info_items(
|
||||
repre_ids
|
||||
)
|
||||
|
|
@ -754,8 +756,7 @@ class SceneInventoryView(QtWidgets.QTreeView):
|
|||
active_version_id = active_repre_info.version_id
|
||||
active_product_id = active_repre_info.product_id
|
||||
version_items_by_product_id = self._controller.get_version_items(
|
||||
product_ids, repre_ids
|
||||
)
|
||||
product_ids, project_names)
|
||||
version_items = list(
|
||||
version_items_by_product_id[active_product_id].values()
|
||||
)
|
||||
|
|
@ -937,6 +938,10 @@ class SceneInventoryView(QtWidgets.QTreeView):
|
|||
container_item.representation_id
|
||||
for container_item in containers_items_by_id.values()
|
||||
}
|
||||
project_names = {
|
||||
container_item.project_name
|
||||
for container_item in containers_items_by_id.values()
|
||||
}
|
||||
repre_info_by_id = self._controller.get_representation_info_items(
|
||||
repre_ids
|
||||
)
|
||||
|
|
@ -946,8 +951,7 @@ class SceneInventoryView(QtWidgets.QTreeView):
|
|||
if repre_info.is_valid
|
||||
}
|
||||
version_items_by_product_id = self._controller.get_version_items(
|
||||
product_ids, repre_ids
|
||||
)
|
||||
product_ids, project_names)
|
||||
|
||||
update_containers = []
|
||||
update_versions = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue