Skip to content

Union of compress & convert statistics#111

Open
tijmenbruggeman wants to merge 5 commits into
tinify:masterfrom
wcreateweb:task/uncompressed-statistics
Open

Union of compress & convert statistics#111
tijmenbruggeman wants to merge 5 commits into
tinify:masterfrom
wcreateweb:task/uncompressed-statistics

Conversation

@tijmenbruggeman
Copy link
Copy Markdown
Collaborator

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.php
    • will simply set the result of the statistics to available-unoptimized-sizes and optimized-image-sizes
    • will only count additional credits when conversion is enabled
  • src/class-tiny-image.php
    • adds image_sizes_optimized and optimized-image-sizes to the statistics.
    • will increment available_unoptimized_sizes when it is either uncompressed or unconverted
    • will increment image_sizes_optimized when it compressed AND converted

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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() with image_sizes_optimized / available_unoptimized_sizes computed 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 thread src/class-tiny-image.php
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();
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.

3 participants