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

EP.io messages adjustments #3376

Merged
merged 5 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions includes/classes/ElasticPressIo.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
* @package ElasticPress
*/
class ElasticPressIo {
/**
* Name of the transient that stores EP.io messages
*/
const MESSAGES_TRANSIENT_NAME = 'ep_elasticpress_io_messages';

/**
* Return singleton instance of class
*
Expand All @@ -36,17 +41,27 @@ public static function factory() {
/**
* Get messages from ElasticPress.io.
*
* @param bool $skip_cache Whether to fetch the API or use the cached messages. Defaults to false, i.e., use cache.
* @return array ElasticPress.io messages.
*/
public function get_endpoint_messages() {
public function get_endpoint_messages( $skip_cache = false ) : array {
if ( ! Utils\is_epio() ) {
return [];
}

$transient = 'ep_elasticpress_io_messages';
$messages = get_transient( $transient );

if ( false !== $messages ) {
if ( ! $skip_cache && false !== $messages ) {
return $messages;
}

$response = \ElasticPress\Elasticsearch::factory()->remote_request( 'endpoint-messages' );

$response_code = wp_remote_retrieve_response_code( $response );
if ( is_wp_error( $response ) || 200 !== $response_code ) {
return [];
}

$messages = (array) json_decode( wp_remote_retrieve_body( $response ), true );

set_transient( $transient, $messages, HOUR_IN_SECONDS );
Expand Down
2 changes: 1 addition & 1 deletion includes/classes/StatusReport/ElasticPressIo.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected function get_instant_results_field() : array {
* @since 4.5.0
*/
public function get_messages() : array {
$messages = \ElasticPress\ElasticPressIo::factory()->get_endpoint_messages();
$messages = \ElasticPress\ElasticPressIo::factory()->get_endpoint_messages( true );
$messages = array_values( $messages );

return $messages;
Expand Down
11 changes: 6 additions & 5 deletions uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ class EP_Uninstaller {
* @var array
*/
protected $transients = [
'ep_autosuggest_query_request_cache',
'ep_elasticpress_io_messages',
'ep_es_info',
'ep_es_info_response_code',
'ep_es_info_response_error',
'logging_ep_es_info',
'ep_wpcli_sync_interrupted',
'ep_wpcli_sync',
'ep_es_info',
'ep_autosuggest_query_request_cache',
'ep_meta_field_keys',
'ep_wpcli_sync',
'ep_wpcli_sync_interrupted',
'logging_ep_es_info',
];

/**
Expand Down