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

Disregard transient cache in perflab_query_plugin_info() when a plugin is absent #1694

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

b1ink0
Copy link
Contributor

@b1ink0 b1ink0 commented Nov 22, 2024

Summary

Fixes #1617

Relevant technical choices

When a new feature plugin is published, it may not yet exist in the transient. Therefore, whenever one of the expected feature plugin is absent, we should act as if the transient was not set in the first place so that we can obtain the latest plugin info right away.

Logic for this to work:

  • If the plugin slug is not found in the transient then instead of returning a error we proceeded to fetch information from API.
  • If the plugin slug is also not found in the API it is also stored in transient but with key as plugin slug and value as false.
  • If the plugin slug is found in the transient but if its value is equal to false raise the error.

This logic will make sure that the multiple request are not made for the plugin which is absent.

@b1ink0 b1ink0 marked this pull request as ready for review November 22, 2024 14:07
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: b1ink0 <[email protected]>
Co-authored-by: swissspidy <[email protected]>
Co-authored-by: felixarntz <[email protected]>
Co-authored-by: westonruter <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter westonruter added this to the performance-lab n.e.x.t milestone Nov 22, 2024
@westonruter westonruter added [Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only [Type] Bug An existing feature is broken [Type] Enhancement A suggestion for improvement of an existing feature and removed [Type] Bug An existing feature is broken labels Nov 22, 2024
__( 'Plugin not found in WordPress.org API response.', 'performance-lab' )
);
// Cache the fact that the plugin was not found.
$plugins[ $current_plugin_slug ] = false;
Copy link
Member

Choose a reason for hiding this comment

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

Instead of storing false here, what about storing the WP_Error instance? As it stands right now, there are two conditions resulting in false being logged, which conflates these two error scenarios which we tried to get rid of in #1651 to assist with debugging.

Copy link
Member

Choose a reason for hiding this comment

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

Overall this makes sense to me. We probably shouldn't store the WP_Error instance though, but just its data, since storing PHP class instances is a bit unpredictable with what would happen in different object cache implementations.

@@ -101,9 +102,14 @@ function perflab_query_plugin_info( string $plugin_slug ) {
}
}

if ( ! isset( $plugins[ $plugin_slug ] ) ) {
// Cache the fact that the plugin was not found.
$plugins[ $plugin_slug ] = false;
Copy link
Member

Choose a reason for hiding this comment

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

See above about storing a WP_Error instance instead.

Comment on lines +27 to +33
if ( false === $plugins[ $plugin_slug ] ) {
// Plugin was requested before and not found.
return new WP_Error(
'plugin_not_found',
__( 'Plugin not found in cached API response.', 'performance-lab' )
);
}
Copy link
Member

Choose a reason for hiding this comment

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

If $plugins[ $plugin_slug ] is either an array or a WP_Error, then this can just return that.

Suggested change
if ( false === $plugins[ $plugin_slug ] ) {
// Plugin was requested before and not found.
return new WP_Error(
'plugin_not_found',
__( 'Plugin not found in cached API response.', 'performance-lab' )
);
}

// Cache the fact that the plugin was not found.
$plugins[ $plugin_slug ] = false;
}

set_transient( $transient_key, $plugins, HOUR_IN_SECONDS );
Copy link
Member

Choose a reason for hiding this comment

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

Here I think it would be good to check if there was an error condition, and if so, set the expiration to 1 minute instead of HOUR_IN_SECONDS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disregard transient cache in perflab_query_plugin_info() when a plugin is absent
3 participants