Skip to content
Open
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
14 changes: 8 additions & 6 deletions src/actions/indexing/indexable-post-indexation-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ protected function get_count_query() {
FROM {$this->wpdb->posts} AS P
WHERE P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $post_types ), '%s' ) ) . ')
AND P.post_status NOT IN (' . \implode( ', ', \array_fill( 0, \count( $excluded_post_statuses ), '%s' ) ) . ")
AND P.ID not in (
SELECT I.object_id from $indexable_table as I
WHERE I.object_type = 'post'
AND NOT EXISTS (
SELECT 1 FROM $indexable_table AS I
WHERE I.object_id = P.ID
AND I.object_type = 'post'
AND I.version = %d )",
$replacements,
);
Expand Down Expand Up @@ -196,9 +197,10 @@ protected function get_select_query( $limit = false ) {
FROM {$this->wpdb->posts} AS P
WHERE P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $post_types ), '%s' ) ) . ')
AND P.post_status NOT IN (' . \implode( ', ', \array_fill( 0, \count( $excluded_post_statuses ), '%s' ) ) . ")
AND P.ID not in (
SELECT I.object_id from $indexable_table as I
WHERE I.object_type = 'post'
AND NOT EXISTS (
SELECT 1 FROM $indexable_table AS I
WHERE I.object_id = P.ID
AND I.object_type = 'post'
AND I.version = %d )
$limit_query",
$replacements,
Expand Down
9 changes: 4 additions & 5 deletions src/integrations/admin/indexing-notification-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ public static function get_conditionals() {
* @return void
*/
public function maybe_create_notification() {
if ( ! $this->should_show_notification() ) {
return;
}

if ( ! $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID ) ) {
if (
! $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID )
&& $this->should_show_notification()
) {
$notification = $this->notification();
$this->notification_helper->restore_notification( $notification );
$this->notification_center->add_notification( $notification );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ public function test_get_total_unindexed() {
FROM wp_posts AS P
WHERE P.post_type IN (%s)
AND P.post_status NOT IN (%s)
AND P.ID not in (
SELECT I.object_id from wp_yoast_indexable as I
WHERE I.object_type = 'post'
AND NOT EXISTS (
SELECT 1 FROM wp_yoast_indexable AS I
WHERE I.object_id = P.ID
AND I.object_type = 'post'
AND I.version = %d )";

Functions\expect( 'get_transient' )->once()->with( 'wpseo_total_unindexed_posts' )->andReturnFalse();
Expand Down Expand Up @@ -147,9 +148,10 @@ public function test_get_limited_unindexed_count() {
FROM wp_posts AS P
WHERE P.post_type IN (%s)
AND P.post_status NOT IN (%s)
AND P.ID not in (
SELECT I.object_id from wp_yoast_indexable as I
WHERE I.object_type = 'post'
AND NOT EXISTS (
SELECT 1 FROM wp_yoast_indexable AS I
WHERE I.object_id = P.ID
AND I.object_type = 'post'
AND I.version = %d )
LIMIT %d";

Expand Down Expand Up @@ -230,9 +232,10 @@ public function test_get_total_unindexed_with_excluded_post_types() {
FROM wp_posts AS P
WHERE P.post_type IN (%s)
AND P.post_status NOT IN (%s)
AND P.ID not in (
SELECT I.object_id from wp_yoast_indexable as I
WHERE I.object_type = 'post'
AND NOT EXISTS (
SELECT 1 FROM wp_yoast_indexable AS I
WHERE I.object_id = P.ID
AND I.object_type = 'post'
AND I.version = %d )";

Functions\expect( 'get_transient' )->once()->with( 'wpseo_total_unindexed_posts' )->andReturnFalse();
Expand Down Expand Up @@ -265,9 +268,10 @@ public function test_index() {
FROM wp_posts AS P
WHERE P.post_type IN (%s)
AND P.post_status NOT IN (%s)
AND P.ID not in (
SELECT I.object_id from wp_yoast_indexable as I
WHERE I.object_type = 'post'
AND NOT EXISTS (
SELECT 1 FROM wp_yoast_indexable AS I
WHERE I.object_id = P.ID
AND I.object_type = 'post'
AND I.version = %d )
LIMIT %d";

Expand Down Expand Up @@ -350,9 +354,10 @@ public function test_index_with_excluded_post_types() {
FROM wp_posts AS P
WHERE P.post_type IN (%s)
AND P.post_status NOT IN (%s)
AND P.ID not in (
SELECT I.object_id from wp_yoast_indexable as I
WHERE I.object_type = 'post'
AND NOT EXISTS (
SELECT 1 FROM wp_yoast_indexable AS I
WHERE I.object_id = P.ID
AND I.object_type = 'post'
AND I.version = %d )
LIMIT %d";

Expand Down Expand Up @@ -405,9 +410,10 @@ public function test_index_no_indexables_created() {
FROM wp_posts AS P
WHERE P.post_type IN (%s)
AND P.post_status NOT IN (%s)
AND P.ID not in (
SELECT I.object_id from wp_yoast_indexable as I
WHERE I.object_type = 'post'
AND NOT EXISTS (
SELECT 1 FROM wp_yoast_indexable AS I
WHERE I.object_id = P.ID
AND I.object_type = 'post'
AND I.version = %d )
LIMIT %d";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ public function test_get_conditionals() {
* @return void
*/
public function test_create_notification_no_unindexed_items() {
$this->notification_center
->expects( 'get_notification_by_id' )
->with( Indexing_Notification_Integration::NOTIFICATION_ID )
->once()
->andReturnFalse();

$this->environment_helper
->expects( 'is_production_mode' )
->andReturn( true );
Expand Down Expand Up @@ -304,6 +310,12 @@ public function test_create_notification_no_unindexed_items() {
* @return void
*/
public function test_create_notification_with_having_indexing_started() {
$this->notification_center
->expects( 'get_notification_by_id' )
->with( Indexing_Notification_Integration::NOTIFICATION_ID )
->once()
->andReturnFalse();

$this->environment_helper
->expects( 'is_production_mode' )
->andReturn( true );
Expand All @@ -323,6 +335,40 @@ public function test_create_notification_with_having_indexing_started() {
$this->instance->maybe_create_notification();
}

/**
* Tests that the expensive should_show_notification check is short-circuited
* when the notification already exists in the notification center.
*
* @covers ::maybe_create_notification
*
* @return void
*/
public function test_maybe_create_notification_skips_expensive_check_when_notification_exists() {
$this->notification_center
->expects( 'get_notification_by_id' )
->with( Indexing_Notification_Integration::NOTIFICATION_ID )
->once()
->andReturn( 'the_notification' );

$this->environment_helper
->expects( 'is_production_mode' )
->never();

$this->indexing_helper
->expects( 'get_started' )
->never();

$this->indexing_helper
->expects( 'get_limited_filtered_unindexed_count' )
->never();

$this->notification_center
->expects( 'add_notification' )
->never();

$this->instance->maybe_create_notification();
}

/**
* Tests creating the notification with the reason being that indexing has failed.
*
Expand Down Expand Up @@ -589,6 +635,12 @@ public function test_maybe_cleanup_notification() {
* @return void
*/
public function test_create_notification_no_prod_site() {
$this->notification_center
->expects( 'get_notification_by_id' )
->with( Indexing_Notification_Integration::NOTIFICATION_ID )
->once()
->andReturnFalse();

$this->environment_helper
->expects( 'is_production_mode' )
->andReturn( false );
Expand Down
Loading
Loading