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

Closes #939: Handle image stats through background processing #943

Conversation

jeawhanlee
Copy link
Contributor

@jeawhanlee jeawhanlee commented Dec 18, 2024

Description

Fixes #939

Fixes issue with time out when collating stats.

Type of change

  • Bug fix (non-breaking change which fixes an issue).
  • Enhancement (non-breaking change which improves an existing functionality).

Detailed scenario

Explained here

Technical description

Documentation

Moves the stats logic from main thread to process in background using Action Scheduler.

New dependencies

N/A

Risks

Displayed stats will not be updated until the next scheduled action in this case 24hr

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots 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.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Unticked items justification

If some mandatory items are not relevant, explain why in this section.

Additional Checks

  • In the case of complex code, I wrote comments to explain it.
  • When possible, I prepared ways to observe the implemented system (logs, data, etc.).
  • I added error handling logic when using functions that could throw errors (HTTP/API request, filesystem, etc.)

@jeawhanlee jeawhanlee self-assigned this Dec 18, 2024
@jeawhanlee jeawhanlee linked an issue Dec 18, 2024 that may be closed by this pull request
@jeawhanlee jeawhanlee marked this pull request as ready for review December 18, 2024 12:49
@jeawhanlee jeawhanlee requested a review from a team December 18, 2024 12:50
Comment on lines +21 to +26
'imagify_count_attachments_as',
'imagify_count_error_attachments_as',
'imagify_count_optimized_attachments_as',
'imagify_count_saving_data_as',
'imagify_calculate_total_size_images_library_as',
'imagify_calculate_average_size_images_per_month_as',
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you have the _as suffix for the actions?

*
* @var string
*/
protected $stats_option = 'imagify_admin_stats';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking this naming is not very accurate, what do you think about imagify_attachments_stats or imagify_media_stats instead?

*
* @return void
*/
public function imagify_count_attachments(): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove the imagify_ prefix from the functions you copied since they're in a class now

* @param integer $default default value to return.
* @return mixed
*/
function imagify_get_admin_stats( string $key, $default = 0 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In relation to the option name change suggested, might be better to use imagify_get_attachments_stats or imagify_get_media_stats

@MathieuLamiot
Copy link
Contributor

As discussed yesterday, @jeawhanlee should this be closed?

@jeawhanlee
Copy link
Contributor Author

Yes, we can close this in favor of this and this
Just leaving this here so when we circle back on enhancing the the bulk optimization page, we have this as a history.

@jeawhanlee jeawhanlee closed this Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle image stats through background processing
3 participants