Use smaller transactions

This commit is contained in:
tcely 2025-03-15 21:05:39 -04:00 committed by GitHub
parent f99c8fc596
commit ec45f29e1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -179,7 +179,6 @@ def cleanup_removed_media(source, videos):
@background(schedule=300, remove_existing_tasks=True) @background(schedule=300, remove_existing_tasks=True)
@atomic(durable=True)
def index_source_task(source_id): def index_source_task(source_id):
''' '''
Indexes media available from a Source object. Indexes media available from a Source object.
@ -210,9 +209,6 @@ def index_source_task(source_id):
verbose_name = task.verbose_name verbose_name = task.verbose_name
tvn_format = '[{}' + f'/{num_videos}] {verbose_name}' tvn_format = '[{}' + f'/{num_videos}] {verbose_name}'
for vn, video in enumerate(videos, start=1): for vn, video in enumerate(videos, start=1):
if task:
task.verbose_name = tvn_format.format(vn)
task.save(update_fields={'verbose_name'})
# Create or update each video as a Media object # Create or update each video as a Media object
key = video.get(source.key_field, None) key = video.get(source.key_field, None)
if not key: if not key:
@ -229,8 +225,12 @@ def index_source_task(source_id):
published_dt = media.metadata_published(timestamp) published_dt = media.metadata_published(timestamp)
if published_dt is not None: if published_dt is not None:
media.published = published_dt media.published = published_dt
if task:
task.verbose_name = tvn_format.format(vn)
try: try:
with atomic(): with atomic():
if task:
task.save(update_fields={'verbose_name'})
media.save() media.save()
log.debug(f'Indexed media: {source} / {media}') log.debug(f'Indexed media: {source} / {media}')
# log the new media instances # log the new media instances