-
Notifications
You must be signed in to change notification settings - Fork 109
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
Changes from 4 commits
d55cf6b
d629ec2
54532b5
c923c97
89b4c7f
2a344c9
46b1216
ff1b440
1d3ef59
80573b6
49692cb
c376ca2
74cc52e
aeb9fe5
74ab1e2
c0fa985
3868965
7709e41
a090c1b
571027b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,14 +23,16 @@ function perflab_query_plugin_info( string $plugin_slug ) { | |
$plugins = get_transient( $transient_key ); | ||
|
||
if ( is_array( $plugins ) ) { | ||
// If the specific plugin_slug is not in the cache, return an error. | ||
if ( ! isset( $plugins[ $plugin_slug ] ) ) { | ||
return new WP_Error( | ||
'plugin_not_found', | ||
__( 'Plugin not found in cached API response.', 'performance-lab' ) | ||
); | ||
if ( isset( $plugins[ $plugin_slug ] ) ) { | ||
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' ) | ||
); | ||
} | ||
return $plugins[ $plugin_slug ]; // Return cached plugin info if found. | ||
} | ||
return $plugins[ $plugin_slug ]; // Return cached plugin info if found. | ||
} | ||
|
||
$fields = array( | ||
|
@@ -86,10 +88,9 @@ function perflab_query_plugin_info( string $plugin_slug ) { | |
} | ||
|
||
if ( ! isset( $all_performance_plugins[ $current_plugin_slug ] ) ) { | ||
return new WP_Error( | ||
'plugin_not_found', | ||
__( 'Plugin not found in WordPress.org API response.', 'performance-lab' ) | ||
); | ||
// Cache the fact that the plugin was not found. | ||
$plugins[ $current_plugin_slug ] = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of storing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall this makes sense to me. We probably shouldn't store the |
||
continue; | ||
} | ||
|
||
$plugin_data = $all_performance_plugins[ $current_plugin_slug ]; | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above about storing a |
||
} | ||
|
||
set_transient( $transient_key, $plugins, HOUR_IN_SECONDS ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
if ( ! isset( $plugins[ $plugin_slug ] ) ) { | ||
if ( false === $plugins[ $plugin_slug ] ) { | ||
return new WP_Error( | ||
'plugin_not_found', | ||
__( 'Plugin not found in API response.', 'performance-lab' ) | ||
|
There was a problem hiding this comment.
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 anarray
or aWP_Error
, then this can just return that.