mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
Merge pull request #2563 from pypeclub/bugfix/OP-2310_Ftrack-Delete-action-revision
Ftrack: Delete action revision
This commit is contained in:
commit
3ebc7fafce
1 changed files with 39 additions and 14 deletions
|
|
@ -163,24 +163,27 @@ class DeleteAssetSubset(BaseAction):
|
|||
|
||||
if not selected_av_entities:
|
||||
return {
|
||||
"success": False,
|
||||
"message": "Didn't found entities in avalon"
|
||||
"success": True,
|
||||
"message": (
|
||||
"Didn't found entities in avalon."
|
||||
" You can use Ftrack's Delete button for the selection."
|
||||
)
|
||||
}
|
||||
|
||||
# Remove cached action older than 2 minutes
|
||||
old_action_ids = []
|
||||
for id, data in self.action_data_by_id.items():
|
||||
for action_id, data in self.action_data_by_id.items():
|
||||
created_at = data.get("created_at")
|
||||
if not created_at:
|
||||
old_action_ids.append(id)
|
||||
old_action_ids.append(action_id)
|
||||
continue
|
||||
cur_time = datetime.now()
|
||||
existing_in_sec = (created_at - cur_time).total_seconds()
|
||||
if existing_in_sec > 60 * 2:
|
||||
old_action_ids.append(id)
|
||||
old_action_ids.append(action_id)
|
||||
|
||||
for id in old_action_ids:
|
||||
self.action_data_by_id.pop(id, None)
|
||||
for action_id in old_action_ids:
|
||||
self.action_data_by_id.pop(action_id, None)
|
||||
|
||||
# Store data for action id
|
||||
action_id = str(uuid.uuid1())
|
||||
|
|
@ -439,7 +442,11 @@ class DeleteAssetSubset(BaseAction):
|
|||
subsets_to_delete = to_delete.get("subsets") or []
|
||||
|
||||
# Convert asset ids to ObjectId obj
|
||||
assets_to_delete = [ObjectId(id) for id in assets_to_delete if id]
|
||||
assets_to_delete = [
|
||||
ObjectId(asset_id)
|
||||
for asset_id in assets_to_delete
|
||||
if asset_id
|
||||
]
|
||||
|
||||
subset_ids_by_parent = spec_data["subset_ids_by_parent"]
|
||||
subset_ids_by_name = spec_data["subset_ids_by_name"]
|
||||
|
|
@ -468,9 +475,8 @@ class DeleteAssetSubset(BaseAction):
|
|||
if not ftrack_id:
|
||||
ftrack_id = asset["data"].get("ftrackId")
|
||||
|
||||
if not ftrack_id:
|
||||
continue
|
||||
ftrack_ids_to_delete.append(ftrack_id)
|
||||
if ftrack_id:
|
||||
ftrack_ids_to_delete.append(ftrack_id)
|
||||
|
||||
children_queue = collections.deque()
|
||||
for mongo_id in assets_to_delete:
|
||||
|
|
@ -569,12 +575,12 @@ class DeleteAssetSubset(BaseAction):
|
|||
exc_info=True
|
||||
)
|
||||
|
||||
if not_deleted_entities_id:
|
||||
joined_not_deleted = ", ".join([
|
||||
if not_deleted_entities_id and asset_names_to_delete:
|
||||
joined_not_deleted = ",".join([
|
||||
"\"{}\"".format(ftrack_id)
|
||||
for ftrack_id in not_deleted_entities_id
|
||||
])
|
||||
joined_asset_names = ", ".join([
|
||||
joined_asset_names = ",".join([
|
||||
"\"{}\"".format(name)
|
||||
for name in asset_names_to_delete
|
||||
])
|
||||
|
|
@ -613,6 +619,25 @@ class DeleteAssetSubset(BaseAction):
|
|||
joined_ids_to_delete
|
||||
)
|
||||
).all()
|
||||
# Find all children entities and add them to list
|
||||
# - Delete tasks first then their parents and continue
|
||||
parent_ids_to_delete = [
|
||||
entity["id"]
|
||||
for entity in to_delete_entities
|
||||
]
|
||||
while parent_ids_to_delete:
|
||||
joined_parent_ids_to_delete = ",".join([
|
||||
"\"{}\"".format(ftrack_id)
|
||||
for ftrack_id in parent_ids_to_delete
|
||||
])
|
||||
_to_delete = session.query((
|
||||
"select id, link from TypedContext where parent_id in ({})"
|
||||
).format(joined_parent_ids_to_delete)).all()
|
||||
parent_ids_to_delete = []
|
||||
for entity in _to_delete:
|
||||
parent_ids_to_delete.append(entity["id"])
|
||||
to_delete_entities.append(entity)
|
||||
|
||||
entities_by_link_len = collections.defaultdict(list)
|
||||
for entity in to_delete_entities:
|
||||
entities_by_link_len[len(entity["link"])].append(entity)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue