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

Prevent doubled requests #3265

Merged
merged 3 commits into from
Jan 19, 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
8 changes: 6 additions & 2 deletions includes/classes/Feature/Autosuggest/Autosuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,9 +894,13 @@ public function epio_autosuggest_set_and_get() {
break;
}

if ( empty( $allowed_params ) ) {
$this->epio_send_autosuggest_public_request( true );
// We have what we need, no need to retry.
if ( ! empty( $allowed_params ) ) {
break;
}

// Send to EP.io what should be autosuggest's allowed values and try to get them again.
$this->epio_send_autosuggest_public_request( true );
}

return $allowed_params;
Expand Down
8 changes: 8 additions & 0 deletions includes/classes/Screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class Screen {
*/
public $health_info_screen;

/**
* Status report instance
*
* @var Screen\StatusReport
* @since 4.5.0
*/
public $status_report;

/**
* Initialize class
*
Expand Down
52 changes: 36 additions & 16 deletions includes/classes/Screen/StatusReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
* @package ElasticPress
*/
class StatusReport {
/**
* The formatted/processed reports.
*
* @since 4.5.0
* @var array
*/
protected $formatted_reports = [];

/**
* Initialize class
*/
Expand Down Expand Up @@ -45,22 +53,10 @@ public function admin_enqueue_scripts() {
true
);

$reports = $this->get_reports();
$reports = array_map(
function( $report ) {
return [
'actions' => $report->get_actions(),
'groups' => $report->get_groups(),
'title' => $report->get_title(),
];
},
$reports
);

wp_localize_script(
'ep_admin_status_report_scripts',
'epStatusReport',
$reports
$this->get_formatted_reports()
);

$style_deps = Utils\get_asset_info( 'status-report-styles', 'dependencies' );
Expand Down Expand Up @@ -128,13 +124,13 @@ function( $report_slug ) use ( $skipped_reports ) {
* Render all reports (HTML and Copy & Paste button)
*/
public function render_reports() {
$reports = $this->get_reports();
$reports = $this->get_formatted_reports();

$copy_paste_output = [];

foreach ( $reports as $report ) {
$title = $report->get_title();
$groups = $report->get_groups();
$title = $report['title'];
$groups = $report['groups'];

$copy_paste_output[] = $this->render_copy_paste_report( $title, $groups );
}
Expand All @@ -152,6 +148,30 @@ public function render_reports() {
<?php
}

/**
* Process and format the reports, then store them in the `formatted_reports` attribute.
*
* @since 4.5.0
* @return array
*/
protected function get_formatted_reports() : array {
if ( empty( $this->formatted_reports ) ) {
$reports = $this->get_reports();

$this->formatted_reports = array_map(
function( $report ) {
return [
'actions' => $report->get_actions(),
'groups' => $report->get_groups(),
'title' => $report->get_title(),
];
},
$reports
);
}
return $this->formatted_reports;
}

/**
* Render the copy & paste report
*
Expand Down
4 changes: 1 addition & 3 deletions includes/partials/status-report-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
* @package elasticpress
*/

use ElasticPress\Screen\StatusReport;

defined( 'ABSPATH' ) || exit;

$status_report = new StatusReport();
$status_report = \ElasticPress\Screen::factory()->status_report;

require_once __DIR__ . '/header.php';
?>
Expand Down