PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
← All changes | src/actions/indexing/post-link-indexing-action.php +43 -35 18.5 → trunk View file →
@@ -6,10 +6,8 @@
6 6 use Yoast\WP\SEO\Helpers\Post_Type_Helper;
7 7
8 8 /**
9 9 * Reindexing action for post link indexables.
10 - *
11 - * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
12 10 */
13 11 class Post_Link_Indexing_Action extends Abstract_Link_Indexing_Action {
14 12
15 13 /**
@@ -16,9 +14,9 @@
16 14 * The transient name.
17 15 *
18 16 * @var string
19 17 */
20 - const UNINDEXED_COUNT_TRANSIENT = 'wpseo_unindexed_post_link_count';
18 + public const UNINDEXED_COUNT_TRANSIENT = 'wpseo_unindexed_post_link_count';
21 19
22 20 /**
23 21 * The transient cache key for limited counts.
24 22 *
@@ -23,9 +21,9 @@
23 21 * The transient cache key for limited counts.
24 22 *
25 23 * @var string
26 24 */
27 - const UNINDEXED_LIMITED_COUNT_TRANSIENT = self::UNINDEXED_COUNT_TRANSIENT . '_limited';
25 + public const UNINDEXED_LIMITED_COUNT_TRANSIENT = self::UNINDEXED_COUNT_TRANSIENT . '_limited';
28 26
29 27 /**
30 28 * The post type helper.
31 29 *
@@ -64,9 +62,9 @@
64 62 'type' => 'post',
65 63 'content' => $post->post_content,
66 64 ];
67 65 },
68 - $posts
66 + $posts,
69 67 );
70 68 }
71 69
72 70 /**
@@ -74,9 +72,9 @@
74 72 *
75 73 * @return string The prepared query string.
76 74 */
77 75 protected function get_count_query() {
78 - $public_post_types = $this->post_type_helper->get_accessible_post_types();
76 + $public_post_types = $this->post_type_helper->get_indexable_post_types();
79 77 $indexable_table = Model::get_table_name( 'Indexable' );
80 78 $links_table = Model::get_table_name( 'SEO_Links' );
81 79
82 80 // Warning: If this query is changed, makes sure to update the query in get_select_query as well.
@@ -82,22 +80,27 @@
82 80 // Warning: If this query is changed, makes sure to update the query in get_select_query as well.
83 81 return $this->wpdb->prepare(
84 82 "SELECT COUNT(P.ID)
85 83 FROM {$this->wpdb->posts} AS P
86 - LEFT JOIN $indexable_table AS I
87 - ON P.ID = I.object_id
88 - AND I.link_count IS NOT NULL
89 - AND I.object_type = 'post'
90 - LEFT JOIN $links_table AS L
91 - ON L.post_id = P.ID
92 - AND L.target_indexable_id IS NULL
93 - AND L.type = 'internal'
94 - AND L.target_post_id IS NOT NULL
95 - AND L.target_post_id != 0
96 - WHERE ( I.object_id IS NULL OR L.post_id IS NOT NULL )
97 - AND P.post_status = 'publish'
98 - AND P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $public_post_types ), '%s' ) ) . ')',
99 - $public_post_types
84 + WHERE P.post_status = 'publish'
85 + AND P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $public_post_types ), '%s' ) ) . ')
86 + AND (
87 + NOT EXISTS (
88 + SELECT 1 FROM ' . $indexable_table . " AS I
89 + WHERE I.object_id = P.ID
90 + AND I.link_count IS NOT NULL
91 + AND I.object_type = 'post'
92 + )
93 + OR EXISTS (
94 + SELECT 1 FROM $links_table AS L
95 + WHERE L.post_id = P.ID
96 + AND L.target_indexable_id IS NULL
97 + AND L.type = 'internal'
98 + AND L.target_post_id IS NOT NULL
99 + AND L.target_post_id != 0
100 + )
101 + )",
102 + $public_post_types,
100 103 );
101 104 }
102 105
103 106 /**
@@ -107,9 +110,9 @@
107 110 *
108 111 * @return string The prepared query string.
109 112 */
110 113 protected function get_select_query( $limit = false ) {
111 - $public_post_types = $this->post_type_helper->get_accessible_post_types();
114 + $public_post_types = $this->post_type_helper->get_indexable_post_types();
112 115 $indexable_table = Model::get_table_name( 'Indexable' );
113 116 $links_table = Model::get_table_name( 'SEO_Links' );
114 117 $replacements = $public_post_types;
115 118
@@ -123,22 +126,27 @@
123 126 return $this->wpdb->prepare(
124 127 "
125 128 SELECT P.ID, P.post_content
126 129 FROM {$this->wpdb->posts} AS P
127 - LEFT JOIN $indexable_table AS I
128 - ON P.ID = I.object_id
129 - AND I.link_count IS NOT NULL
130 - AND I.object_type = 'post'
131 - LEFT JOIN $links_table AS L
132 - ON L.post_id = P.ID
133 - AND L.target_indexable_id IS NULL
134 - AND L.type = 'internal'
135 - AND L.target_post_id IS NOT NULL
136 - AND L.target_post_id != 0
137 - WHERE ( I.object_id IS NULL OR L.post_id IS NOT NULL )
138 - AND P.post_status = 'publish'
139 - AND P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $public_post_types ), '%s' ) ) . ")
130 + WHERE P.post_status = 'publish'
131 + AND P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $public_post_types ), '%s' ) ) . ')
132 + AND (
133 + NOT EXISTS (
134 + SELECT 1 FROM ' . $indexable_table . " AS I
135 + WHERE I.object_id = P.ID
136 + AND I.link_count IS NOT NULL
137 + AND I.object_type = 'post'
138 + )
139 + OR EXISTS (
140 + SELECT 1 FROM $links_table AS L
141 + WHERE L.post_id = P.ID
142 + AND L.target_indexable_id IS NULL
143 + AND L.type = 'internal'
144 + AND L.target_post_id IS NOT NULL
145 + AND L.target_post_id != 0
146 + )
147 + )
140 148 $limit_query",
141 - $replacements
149 + $replacements,
142 150 );
143 151 }
144 152 }