Skip to content
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
62 changes: 36 additions & 26 deletions src/actions/indexing/post-link-indexing-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,24 @@ protected function get_count_query() {
return $this->wpdb->prepare(
"SELECT COUNT(P.ID)
FROM {$this->wpdb->posts} AS P
LEFT JOIN $indexable_table AS I
ON P.ID = I.object_id
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
LEFT JOIN $links_table AS L
ON L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
WHERE ( I.object_id IS NULL OR L.post_id IS NOT NULL )
AND P.post_status = 'publish'
AND P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $public_post_types ), '%s' ) ) . ')',
WHERE P.post_status = 'publish'
AND P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $public_post_types ), '%s' ) ) . ')
AND (
NOT EXISTS (
SELECT 1 FROM ' . $indexable_table . " AS I
WHERE I.object_id = P.ID
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
)
OR EXISTS (
SELECT 1 FROM $links_table AS L
WHERE L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
)
)",
$public_post_types,
);
}
Expand Down Expand Up @@ -122,19 +127,24 @@ protected function get_select_query( $limit = false ) {
"
SELECT P.ID, P.post_content
FROM {$this->wpdb->posts} AS P
LEFT JOIN $indexable_table AS I
ON P.ID = I.object_id
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
LEFT JOIN $links_table AS L
ON L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
WHERE ( I.object_id IS NULL OR L.post_id IS NOT NULL )
AND P.post_status = 'publish'
AND P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $public_post_types ), '%s' ) ) . ")
WHERE P.post_status = 'publish'
AND P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $public_post_types ), '%s' ) ) . ')
AND (
NOT EXISTS (
SELECT 1 FROM ' . $indexable_table . " AS I
WHERE I.object_id = P.ID
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
)
OR EXISTS (
SELECT 1 FROM $links_table AS L
WHERE L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
)
)
$limit_query",
$replacements,
);
Expand Down
149 changes: 87 additions & 62 deletions tests/Unit/Actions/Indexing/Post_Link_Indexing_Action_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,24 @@ public function test_get_total_unindexed() {

$expected_query = "SELECT COUNT(P.ID)
FROM wp_posts AS P
LEFT JOIN wp_yoast_indexable AS I
ON P.ID = I.object_id
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
LEFT JOIN wp_yoast_seo_links AS L
ON L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
WHERE ( I.object_id IS NULL OR L.post_id IS NOT NULL )
AND P.post_status = 'publish'
AND P.post_type IN (%s, %s)";
WHERE P.post_status = 'publish'
AND P.post_type IN (%s, %s)
AND (
NOT EXISTS (
SELECT 1 FROM wp_yoast_indexable AS I
WHERE I.object_id = P.ID
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
)
OR EXISTS (
SELECT 1 FROM wp_yoast_seo_links AS L
WHERE L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
)
)";

$this->wpdb
->expects( 'prepare' )
Expand Down Expand Up @@ -192,19 +197,24 @@ public function test_get_limited_unindexed_count() {

$expected_query = "SELECT COUNT(P.ID)
FROM wp_posts AS P
LEFT JOIN wp_yoast_indexable AS I
ON P.ID = I.object_id
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
LEFT JOIN wp_yoast_seo_links AS L
ON L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
WHERE ( I.object_id IS NULL OR L.post_id IS NOT NULL )
AND P.post_status = 'publish'
AND P.post_type IN (%s, %s)";
WHERE P.post_status = 'publish'
AND P.post_type IN (%s, %s)
AND (
NOT EXISTS (
SELECT 1 FROM wp_yoast_indexable AS I
WHERE I.object_id = P.ID
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
)
OR EXISTS (
SELECT 1 FROM wp_yoast_seo_links AS L
WHERE L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
)
)";

$this->wpdb
->expects( 'prepare' )
Expand Down Expand Up @@ -254,19 +264,24 @@ public function test_index() {
$expected_query = "
SELECT P.ID, P.post_content
FROM wp_posts AS P
LEFT JOIN wp_yoast_indexable AS I
ON P.ID = I.object_id
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
LEFT JOIN wp_yoast_seo_links AS L
ON L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
WHERE ( I.object_id IS NULL OR L.post_id IS NOT NULL )
AND P.post_status = 'publish'
WHERE P.post_status = 'publish'
AND P.post_type IN (%s, %s)
AND (
NOT EXISTS (
SELECT 1 FROM wp_yoast_indexable AS I
WHERE I.object_id = P.ID
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
)
OR EXISTS (
SELECT 1 FROM wp_yoast_seo_links AS L
WHERE L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
)
)
LIMIT %d";

$this->wpdb
Expand Down Expand Up @@ -318,19 +333,24 @@ public function test_index_without_link_count() {
$expected_query = "
SELECT P.ID, P.post_content
FROM wp_posts AS P
LEFT JOIN wp_yoast_indexable AS I
ON P.ID = I.object_id
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
LEFT JOIN wp_yoast_seo_links AS L
ON L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
WHERE ( I.object_id IS NULL OR L.post_id IS NOT NULL )
AND P.post_status = 'publish'
WHERE P.post_status = 'publish'
AND P.post_type IN (%s, %s)
AND (
NOT EXISTS (
SELECT 1 FROM wp_yoast_indexable AS I
WHERE I.object_id = P.ID
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
)
OR EXISTS (
SELECT 1 FROM wp_yoast_seo_links AS L
WHERE L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
)
)
LIMIT %d";

$this->wpdb
Expand Down Expand Up @@ -396,19 +416,24 @@ public function test_index_no_indexables_created() {
$expected_query = "
SELECT P.ID, P.post_content
FROM wp_posts AS P
LEFT JOIN wp_yoast_indexable AS I
ON P.ID = I.object_id
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
LEFT JOIN wp_yoast_seo_links AS L
ON L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
WHERE ( I.object_id IS NULL OR L.post_id IS NOT NULL )
AND P.post_status = 'publish'
WHERE P.post_status = 'publish'
AND P.post_type IN (%s, %s)
AND (
NOT EXISTS (
SELECT 1 FROM wp_yoast_indexable AS I
WHERE I.object_id = P.ID
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
)
OR EXISTS (
SELECT 1 FROM wp_yoast_seo_links AS L
WHERE L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
)
)
LIMIT %d";

$this->wpdb
Expand Down
Loading