From ed55710f26e08657f206aef48080eb2f28a5319b Mon Sep 17 00:00:00 2001 From: tcely Date: Mon, 19 May 2025 08:54:21 -0400 Subject: [PATCH] Create a set of keys for `cleanup_removed_media` --- tubesync/sync/tasks.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tubesync/sync/tasks.py b/tubesync/sync/tasks.py index b192ccfb..6d0727c0 100644 --- a/tubesync/sync/tasks.py +++ b/tubesync/sync/tasks.py @@ -255,7 +255,7 @@ def cleanup_old_media(): schedule_media_servers_update() -def cleanup_removed_media(source, videos): +def cleanup_removed_media(source, video_keys): if not source.delete_removed_media: return log.info(f'Cleaning up media no longer in source: {source}') @@ -265,8 +265,7 @@ def cleanup_removed_media(source, videos): source=source, ) for media in qs_gen(mqs): - matching_source_item = [video['id'] for video in videos if video['id'] == media.key] - if not matching_source_item: + if media.key not in video_keys: log.info(f'{media.name} is no longer in source, removing') with atomic(): media.delete() @@ -317,6 +316,7 @@ def index_source_task(source_id): ) tvn_format = '{:,}' + f'/{num_videos:,}' vn = 0 + video_keys = set() while len(videos) > 0: vn += 1 video = videos.popleft() @@ -325,6 +325,7 @@ def index_source_task(source_id): if not key: # Video has no unique key (ID), it can't be indexed continue + video_keys.add(key) update_task_status(task, tvn_format.format(vn)) # media, new_media = Media.objects.get_or_create(key=key, source=source) try: @@ -379,7 +380,7 @@ def index_source_task(source_id): # Reset task.verbose_name to the saved value update_task_status(task, None) # Cleanup of media no longer available from the source - cleanup_removed_media(source, videos) + cleanup_removed_media(source, video_keys) videos = video = None