wp-media / imagify-plugin

Speed up your website with lighter images without losing quality.
https://imagify.io
69 stars 24 forks source link

Fix "workin on" messaging around the Generate Missing webp feature #652

Open iCaspar opened 2 years ago

iCaspar commented 2 years ago

Subtask of #549

From @joejoe04:

To start, I upload 2 images to the Media Library with WebP creation disabled and allow them to optimize. After doing this, I see the settings page say there are 2 images with missing WebP versions. Then I enable WebP creation and delete the backup version of one of the images.

When doing this and clicking "Generate Missing WebP Versions" I see this (even though it says there are 2 missing WebP versions, the tool displays that it is working on 0/1 images.

https://user-images.githubusercontent.com/45705494/145212113-487a228b-a66c-47d1-9aed-a8f6ad6c68d1.png

iCaspar commented 2 years ago

Reproduced: ✔️

Root cause: The denominator in the progress bar text is determined by the response from an ajax call to the getMediaIds action. However, the "It seems you have X" count is populated from a cached stat (which is loaded in a transient up to 2 days old). So changes to the backup status since the transient was created will not be reflected in the "It seems" message.

Furthermore, the "It seems" messaging is not updated until the transient is cleared AND the page is reloaded, because there is no mechanism in the options.js to update that element after the webp generation completes.

Proposed Solution: Provide a mechanism in options.js::fetchIDs() to update the "It seems..." number (1) at the beginning of the webp generation using the updated value for this.totalMedia to reload the number there with the same number as is loaded into the X/N progress text; and (2) update it again when the process completes and the transient has been cleared, to either update the number of missing webp, or hide if no remaining webp can be generated.

Estimate Effort [S]