Merge pull request #707 from tcely/patch-14

Do not schedule additional `download_media` tasks
This commit is contained in:
meeb 2025-02-12 05:47:40 +11:00 committed by GitHub
commit 9894dc2261
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,7 +14,7 @@ from .tasks import (delete_task_by_source, delete_task_by_media, index_source_ta
map_task_to_instance, check_source_directory_exists, map_task_to_instance, check_source_directory_exists,
download_media, rescan_media_server, download_source_images, download_media, rescan_media_server, download_source_images,
save_all_media_for_source, rename_all_media_for_source, save_all_media_for_source, rename_all_media_for_source,
get_media_metadata_task) get_media_metadata_task, get_media_download_task)
from .utils import delete_file, glob_quote from .utils import delete_file, glob_quote
from .filtering import filter_media from .filtering import filter_media
@ -156,8 +156,9 @@ def media_post_save(sender, instance, created, **kwargs):
post_save.disconnect(media_post_save, sender=Media) post_save.disconnect(media_post_save, sender=Media)
instance.save() instance.save()
post_save.connect(media_post_save, sender=Media) post_save.connect(media_post_save, sender=Media)
existing_media_metadata_task = get_media_metadata_task(str(instance.pk))
# If the media is missing metadata schedule it to be downloaded # If the media is missing metadata schedule it to be downloaded
if not instance.metadata and not instance.skip and not get_media_metadata_task(instance.pk): if not (instance.skip or instance.metadata or existing_media_metadata_task):
log.info(f'Scheduling task to download metadata for: {instance.url}') log.info(f'Scheduling task to download metadata for: {instance.url}')
verbose_name = _('Downloading metadata for "{}"') verbose_name = _('Downloading metadata for "{}"')
download_media_metadata( download_media_metadata(
@ -183,13 +184,13 @@ def media_post_save(sender, instance, created, **kwargs):
verbose_name=verbose_name.format(instance.name), verbose_name=verbose_name.format(instance.name),
remove_existing_tasks=True remove_existing_tasks=True
) )
existing_media_download_task = get_media_download_task(str(instance.pk))
# If the media has not yet been downloaded schedule it to be downloaded # If the media has not yet been downloaded schedule it to be downloaded
if not instance.media_file_exists: if not (instance.media_file_exists or existing_media_download_task):
instance.downloaded = False instance.downloaded = False
instance.media_file = None instance.media_file = None
if (not instance.downloaded and instance.can_download and not instance.skip if (instance.source.download_media and instance.can_download) and not (
and instance.source.download_media): instance.skip or instance.downloaded or existing_media_download_task):
delete_task_by_media('sync.tasks.download_media', (str(instance.pk),))
verbose_name = _('Downloading media for "{}"') verbose_name = _('Downloading media for "{}"')
download_media( download_media(
str(instance.pk), str(instance.pk),