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

Ftrack: Delete action revision #2563

Merged
merged 4 commits into from
Jan 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,27 @@ def interface(self, session, entities, event):

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())
Expand Down Expand Up @@ -439,7 +442,11 @@ def launch(self, session, entities, event):
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"]
Expand Down Expand Up @@ -468,9 +475,8 @@ def launch(self, session, entities, event):
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:
Expand Down Expand Up @@ -569,12 +575,12 @@ def launch(self, session, entities, event):
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
])
Expand Down Expand Up @@ -613,6 +619,25 @@ def _filter_entities_to_delete(self, ftrack_ids_to_delete, session):
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)
Expand Down