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

Fix/830 bulk optimisation #832

Merged
merged 4 commits into from
Mar 4, 2024
Merged

Conversation

Khadreal
Copy link
Contributor

@Khadreal Khadreal commented Feb 29, 2024

Description

Fixes #830

Documentation

User documentation

This allow users don't to bulk optimise images that aren't optimise.

Technical documentation

Explain how this code works. Diagram & drawings are welcomed.

Type of change

  • Bug fix (non-breaking change which fixes an issue).

New dependencies

N/A

Risks

List possible performance & security issues or risks, and explain how they have been mitigated.

Checklists

Feature validation

  • I validated all the Acceptance Criteria. If possible, provide sreenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Documentation

  • I prepared the user documentation for the feature/enhancement and shared it in the PR or the GitHub issue.
  • The user documentation covers new/changed entry points (endpoints, WP hooks, configuration files, ...).
  • I prepared the technical documentation if needed, and shared it in the PR or the GitHub issue.

Code style

  • I wrote self-explanatory code about what it does.
  • I wrote comments to explain why it does it.
  • I named variables and functions explicitely.
  • I protected entry points against unexpected inputs.
  • I did not introduce unecessary complexity.
  • I listed the introduced external dependencies explicitely on the PR.
  • I validated the repo-specific guidelines from CONTRIBUTING.md.

@Khadreal Khadreal requested a review from a team February 29, 2024 14:34
@Khadreal Khadreal self-assigned this Feb 29, 2024
@MathieuLamiot MathieuLamiot linked an issue Feb 29, 2024 that may be closed by this pull request
@Miraeld
Copy link
Contributor

Miraeld commented Feb 29, 2024

I've tried this scenario:

1 - Upload some images,
2 - Install Imagify
3 - Enable AVIF
4 - Start a bulk optimization
5 - AVIF are generated.

👍

Comment on lines 186 to 188
$result = $this->get_bulk_instance( $context )->get_optimized_media_ids_without_format( $format );
$media_ids['ids'] = array_merge( $media_ids['ids'], $result['ids'] );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we looping on the formats and optimized media without formats? This is not the purpose of this method. I think only getting the unoptimized media is enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was added as part of the solution for avif that aren't automatically generated after enabling the option

@Miraeld I think you might want to expatiate further, since it was part of the #796

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's not needed anymore after the change from latest PR #828

Copy link
Contributor

Choose a reason for hiding this comment

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

If I may,
The problem of the method get_optimized_media_ids_without_format($format) is that the SQL query within this method only look for the media that have already been optimized by Imagify but without the format.

So in the following scenario:
1 - Upload some images,
2 - Install Imagify
3 - Enable AVIF
4 - Start a bulk optimization

It won't work, as the uploaded image have never been optimized by Imagify, so in the database we won't have any _imagify_status or _imagify_data within the wp_postmeta table.

While the function get_unoptimized_media_ids doesn't care about these 2 metas values. And in the precedent scenario it will gets the IDs of these images and be able to convert them.

Copy link
Contributor

Choose a reason for hiding this comment

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

With get_unoptimized_media_ids(), it will optimize the image and generate any next-gen image too at the same time. For me that's enough, and that is the behaviour that was in previous versions

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the catch and details provided here @Tabrisrp.
Since the PR has been tested and the expected behavior is now OK, are you OK with opening a dedicated issue to try and remove the get_optimized_media_ids_without_format loop part?
This for loop might impact performances but that's only when doing bulk optimization so I think it's acceptable.
This would allow to move forward with the PR and 2.2 without having to re-test, and possible regressions for now ; and keep that optimization for the next Imagify minor (which should be soon anyway).

Copy link
Contributor

Choose a reason for hiding this comment

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

follow up PR opened here #842

@Mai-Saad
Copy link

Mai-Saad commented Mar 1, 2024

Working fine now so if no further changes we can merge it.

@Mai-Saad Mai-Saad merged commit 22e543c into feature/avif Mar 4, 2024
2 checks passed
@Mai-Saad Mai-Saad deleted the fix/830-bulk-optimisation branch March 4, 2024 15:29
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.

Bulk optimization isnot working
5 participants