diff --git a/src/integrations/admin/indexing-notification-integration.php b/src/integrations/admin/indexing-notification-integration.php index 54e38f43044..1a3350f614a 100644 --- a/src/integrations/admin/indexing-notification-integration.php +++ b/src/integrations/admin/indexing-notification-integration.php @@ -229,6 +229,10 @@ protected function should_show_notification() { if ( ! $this->environment_helper->is_production_mode() ) { return false; } + // Do not show optimization notification if the number of unindexed objects is less than 10 or less than 4% of the total objects number. + if ( ! $this->indexing_helper->should_show_optimization_button() ) { + return false; + } // Don't show a notification if the indexing has already been started earlier. if ( $this->indexing_helper->get_started() > 0 ) { return false; diff --git a/tests/unit/integrations/admin/indexing-notification-integration-test.php b/tests/unit/integrations/admin/indexing-notification-integration-test.php index 47ff61640fa..b6d4e68e89f 100644 --- a/tests/unit/integrations/admin/indexing-notification-integration-test.php +++ b/tests/unit/integrations/admin/indexing-notification-integration-test.php @@ -264,6 +264,10 @@ public function test_create_notification_no_unindexed_items() { ->expects( 'is_production_mode' ) ->andReturn( true ); + $this->indexing_helper + ->expects( 'should_show_optimization_button' ) + ->andReturn( true ); + $this->indexing_helper ->expects( 'get_started' ) ->andReturn( 0 ); @@ -293,6 +297,11 @@ public function test_create_notification_with_having_indexing_started() { ->expects( 'is_production_mode' ) ->andReturn( true ); + $this->indexing_helper + ->expects( 'should_show_optimization_button' ) + ->andReturn( true ); + + $this->indexing_helper ->expects( 'get_started' ) ->andReturn( 123456789 ); @@ -320,6 +329,10 @@ public function test_maybe_create_notification_with_indexing_failed_reason() { ->expects( 'is_production_mode' ) ->andReturn( true ); + $this->indexing_helper + ->expects( 'should_show_optimization_button' ) + ->andReturn( true ); + $this->indexing_helper ->expects( 'get_started' ) ->andReturn( 0 ); @@ -371,6 +384,10 @@ public function test_maybe_create_notification_with_indexing_reasons( $reason ) ->expects( 'is_production_mode' ) ->andReturn( true ); + $this->indexing_helper + ->expects( 'should_show_optimization_button' ) + ->andReturn( true ); + $this->indexing_helper ->expects( 'get_started' ) ->andReturn( 0 ); @@ -454,6 +471,10 @@ public function test_maybe_cleanup_notification_when_there_is_something_to_index ->expects( 'is_production_mode' ) ->andReturn( true ); + $this->indexing_helper + ->expects( 'should_show_optimization_button' ) + ->andReturn( true ); + $this->notification_center ->expects( 'get_notification_by_id' ) ->once() @@ -489,6 +510,11 @@ public function test_maybe_cleanup_notification_when_the_user_has_started_indexi ->expects( 'is_production_mode' ) ->andReturn( true ); + $this->indexing_helper + ->expects( 'should_show_optimization_button' ) + ->andReturn( true ); + + $this->notification_center ->expects( 'get_notification_by_id' ) ->once() @@ -521,6 +547,10 @@ public function test_maybe_cleanup_notification() { ->expects( 'is_production_mode' ) ->andReturn( true ); + $this->indexing_helper + ->expects( 'should_show_optimization_button' ) + ->andReturn( true ); + $this->notification_center ->expects( 'get_notification_by_id' ) ->once() @@ -556,6 +586,7 @@ public function test_create_notification_no_prod_site() { ->expects( 'is_production_mode' ) ->andReturn( false ); + $this->notification_center ->expects( 'add_notification' ) ->never();