django-pictures icon indicating copy to clipboard operation
django-pictures copied to clipboard

Add command for regenerating pictures

Open amureki opened this issue 1 year ago • 2 comments

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

amureki avatar Jan 31 '24 13:01 amureki

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 :warning:
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%) :arrow_down:
cleanup 79.75% <0.00%> (-5.22%) :arrow_down:
dj4.1 79.75% <0.00%> (-5.22%) :arrow_down:
dj4.2 79.75% <0.00%> (-5.22%) :arrow_down:
django-rq 79.14% <0.00%> (-5.18%) :arrow_down:
dramatiq 79.14% <0.00%> (-5.18%) :arrow_down:
drf 89.36% <0.00%> (-3.45%) :arrow_down:
macos-latest 79.95% <0.00%> (-5.23%) :arrow_down:
py3.10 79.75% <0.00%> (-5.22%) :arrow_down:
py3.12 79.75% <0.00%> (-5.22%) :arrow_down:
py3.8 79.75% <0.00%> (-5.22%) :arrow_down:
py3.9 79.75% <0.00%> (-5.22%) :arrow_down:
ubuntu-latest 79.75% <0.00%> (-5.22%) :arrow_down:
windows-latest 70.14% <0.00%> (-6.90%) :arrow_down:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jan 31 '24 13:01 codecov[bot]

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

codingjoe avatar Feb 09 '24 17:02 codingjoe

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

codingjoe avatar May 25 '24 09:05 codingjoe