Skip to content

Commit

Permalink
Move skip message logic
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarssanchez committed Feb 22, 2022
1 parent 8304757 commit 993fe3b
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions includes/classes/IndexHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,11 @@ protected function index_objects() {
$this->temporary_wp_actions = $wp_actions;

$this->current_query = $this->get_objects_to_index();
$is_offsetting = 0 !== $this->index_meta['offset'];

$this->index_meta['found_items'] = (int) $this->current_query['total_objects'];

$this->index_meta['from'] = $is_offsetting ? $this->index_meta['offset'] : 1;
$this->index_meta['show_skip_message'] = $is_offsetting && ! isset( $this->index_meta['show_skip_message'] );
$this->index_meta['found_items'] = (int) $this->current_query['total_objects'];
$this->index_meta['current_sync_item']['total'] = $this->index_meta['found_items'];

if ( $this->index_meta['found_items'] && $this->index_meta['offset'] < $this->index_meta['found_items'] ) {
Expand Down Expand Up @@ -648,34 +650,27 @@ function( $item ) {
}
}

$from = $this->index_meta['offset'] - count( $this->current_query['objects'] );

if ( 0 !== $from && empty( $this->index_meta['skip_message_shown'] ) ) {
if ( isset( $this->index_meta['show_skip_message'] ) && $this->index_meta['show_skip_message'] ) {
$this->output(
sprintf(
/* translators: 1. Number of objects indexed */
esc_html__( 'Skipping %1$d %2$s posts...', 'elasticpress' ),
$from,
esc_html__( 'Skipping %1$d %2$s...', 'elasticpress' ),
$this->index_meta['from'],
esc_html( strtolower( $indexable->labels['plural'] ) )
),
'info',
'index_next_batch'
);
}

// From can never actually be 0, as we can't process post number 0.
if ( 0 === $from ) {
$from = 1;
$this->index_meta['show_skip_message'] = false;
}

$this->index_meta['skip_message_shown'] = true;

$this->output(
sprintf(
/* translators: 1. Number of objects indexed, 2. Total number of objects, 3. Last object ID */
esc_html__( 'Processed %1$s %2$d - %3$d of %4$d. Last Object ID: %5$d', 'elasticpress' ),
esc_html( strtolower( $indexable->labels['plural'] ) ),
$from,
$this->index_meta['from'],
$this->index_meta['offset'],
$this->index_meta['found_items'],
$this->index_meta['current_sync_item']['last_processed_object_id']
Expand Down

0 comments on commit 993fe3b

Please sign in to comment.