Union of compress & convert statistics#111
Open
tijmenbruggeman wants to merge 5 commits into
Open
Conversation
rkoopmans
approved these changes
Jun 4, 2026
There was a problem hiding this comment.
Pull request overview
Updates how “optimized” image sizes are counted by treating an image size as optimized only when it is compressed and (when conversion is enabled) also converted, fixing cases where external file changes made conversion-only statistics inaccurate.
Changes:
- Extend
Tiny_Image::get_statistics()withimage_sizes_optimized/available_unoptimized_sizescomputed as a union of compression+conversion needs. - Adjust bulk optimization aggregation to use the new “optimized/unoptimized” counters and only add conversion credits when conversion is enabled.
- Update unit tests to assert the new statistics fields and behavior for conversion on/off.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/class-tiny-image.php |
Adds optimized/unoptimized counters and updates per-size classification logic based on compression + (optional) conversion. |
src/class-tiny-bulk-optimization.php |
Aggregates bulk stats using the new optimized/unoptimized counters; tweaks estimated credit calculation when conversion is enabled. |
test/unit/TinyImageTest.php |
Splits statistics assertions into conversion-disabled vs conversion-enabled tests and asserts new keys. |
test/unit/TinyImageEmptyTest.php |
Updates expected statistics to include the new optimized/unoptimized keys. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
484
to
+489
| $this->statistics['image_sizes_converted'] = 0; | ||
| $this->statistics['available_unconverted_sizes'] = 0; | ||
| $this->statistics['image_sizes_optimized'] = 0; | ||
| $this->statistics['available_unoptimized_sizes'] = 0; | ||
|
|
||
| $conversion_enabled = $this->settings->get_conversion_enabled(); |
Comment on lines
158
to
+162
| public function test_get_statistics() { | ||
| $active_sizes = $this->settings->get_sizes(); | ||
| $active_tinify_sizes = $this->settings->get_active_tinify_sizes(); | ||
| $this->wp->addOption( 'tinypng_convert_format', array( | ||
| 'convert' => 'off', | ||
| ) ); | ||
| $settings = new Tiny_Settings(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When conversion was enabled, the image statistics assumed a image was "optimized" when it was converted. This works because you cannot convert without compressing. But it stops working when the image is modified externally making it compressed but still converted.
This change changes the definition of optimized. An image is optimised when it is converted and compressed.
Changes
src/class-tiny-bulk-optimization.phpsrc/class-tiny-image.phpimage_sizes_optimizedandoptimized-image-sizesto the statistics.available_unoptimized_sizeswhen it is either uncompressed or unconvertedimage_sizes_optimizedwhen it compressed AND converted