Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce number of DB queries while transferring a project to another user #5142

Open
wants to merge 1 commit into
base: release/2.024.25
Choose a base branch
from

Conversation

noliveleger
Copy link
Contributor

Description

Try to avoid running one update query per attachment while maintaining the atomicity of the transaction.

Notes

The former choice to run Attachment.save() right after .move() was done in purpose. The idea was to be sure that the new path of the file was saved in the DB before processing another file. Unfortunately, this created as many DB queries as there were existing attachments (or media files), which was slowing down the process even more. Using bulk_update is (way) more efficient. Using the try/finally block should ensure the atomicity if an error occurs while looping on attachments (or media files).

resume_failed_transfers_2_024_25_fix has been revisited. The call of the command update_attachment_storage_bytes was useless because counters were not affected by the bug and were still accurate.
Moving files are now wrapped in try/except to avoid the command to crash if one transfer cannot be fixed

when moving files from one user's storage to another
Copy link
Contributor

@rgraber rgraber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syntax error when moving media files


if media_files_to_update:
AssetFile.objects.bulk_update(
media_files_to_update, update_fields=['content', 'metadata']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be fields not update_fields

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants