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

Add command for regenerating pictures #153

Closed
wants to merge 1 commit into from

Conversation

amureki
Copy link
Collaborator

@amureki amureki commented Jan 31, 2024

Hey Johannes,

thanks again for the lib!

In my use case, I had my async worker failed several times due to the memory issues when migrating via AlterPictureField.
As a recovery solution, I was following the steps that are done in the migration and ran the following script on a bigger server premises:

for obj in MyModel.objects.exclude(image='').iterator():
    obj.image.update_all(
        from_aspect_ratios=PictureFieldFile.get_picture_files(
            file_name=obj.image.name,
            img_width=obj.image.width,
            img_height=obj.image.height,
            storage=obj.image.storage,
            field=obj.__class__._meta.get_field("image"),
        )
    )

I am proposing to add this as a management command to have a simpler way of recreating the thumbnails.
Here is a draft, happy to finalize it, rework if needed and add tests, but only if you accept it. :)

Best,
Rust

Copy link

codecov bot commented Jan 31, 2024

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (33562b8) 100.00% compared to head (769bc50) 96.11%.
Report is 2 commits behind head on main.

Files Patch % Lines
...ictures/management/commands/regenerate_pictures.py 0.00% 19 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #153      +/-   ##
===========================================
- Coverage   100.00%   96.11%   -3.89%     
===========================================
  Files           13       14       +1     
  Lines          459      489      +30     
===========================================
+ Hits           459      470      +11     
- Misses           0       19      +19     
Flag Coverage Δ
celery 79.14% <0.00%> (-5.18%) ⬇️
cleanup 79.75% <0.00%> (-5.22%) ⬇️
dj4.1 79.75% <0.00%> (-5.22%) ⬇️
dj4.2 79.75% <0.00%> (-5.22%) ⬇️
django-rq 79.14% <0.00%> (-5.18%) ⬇️
dramatiq 79.14% <0.00%> (-5.18%) ⬇️
drf 89.36% <0.00%> (-3.45%) ⬇️
macos-latest 79.95% <0.00%> (-5.23%) ⬇️
py3.10 79.75% <0.00%> (-5.22%) ⬇️
py3.12 79.75% <0.00%> (-5.22%) ⬇️
py3.8 79.75% <0.00%> (-5.22%) ⬇️
py3.9 79.75% <0.00%> (-5.22%) ⬇️
ubuntu-latest 79.75% <0.00%> (-5.22%) ⬇️
windows-latest 70.14% <0.00%> (-6.90%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codingjoe
Copy link
Owner

codingjoe commented Feb 9, 2024

@amureki you should check the migration implementation. You don't need to reinvent the wheel here. If said wheel, is a hypersphere ;)

@codingjoe
Copy link
Owner

Since I didn't see much activity here @amureki I will close this PR. Feel free to pick it up anytime.

@codingjoe codingjoe closed this May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants