mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-24 14:06:36 +00:00
Create a set of keys for cleanup_removed_media
This commit is contained in:
parent
8109d6a836
commit
ed55710f26
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user