← All changes
|
src/actions/indexing/indexable-post-indexation-action.php
+21
-34
18.7
→
trunk
View file →
| @@ -11,10 +11,8 @@ | ||
| 11 | 11 | use Yoast\WP\SEO\Values\Indexables\Indexable_Builder_Versions; |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Reindexing action for post indexables. |
| 15 | - * | |
| 16 | - * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded | |
| 17 | 15 | */ |
| 18 | 16 | class Indexable_Post_Indexation_Action extends Abstract_Indexing_Action { |
| 19 | 17 | |
| 20 | 18 | /** |
| @@ -21,9 +19,9 @@ | ||
| 21 | 19 | * The transient cache key. |
| 22 | 20 | * |
| 23 | 21 | * @var string |
| 24 | 22 | */ |
| 25 | - const UNINDEXED_COUNT_TRANSIENT = 'wpseo_total_unindexed_posts'; | |
| 23 | + public const UNINDEXED_COUNT_TRANSIENT = 'wpseo_total_unindexed_posts'; | |
| 26 | 24 | |
| 27 | 25 | /** |
| 28 | 26 | * The transient cache key for limited counts. |
| 29 | 27 | * |
| @@ -28,9 +26,9 @@ | ||
| 28 | 26 | * The transient cache key for limited counts. |
| 29 | 27 | * |
| 30 | 28 | * @var string |
| 31 | 29 | */ |
| 32 | - const UNINDEXED_LIMITED_COUNT_TRANSIENT = self::UNINDEXED_COUNT_TRANSIENT . '_limited'; | |
| 30 | + public const UNINDEXED_LIMITED_COUNT_TRANSIENT = self::UNINDEXED_COUNT_TRANSIENT . '_limited'; | |
| 33 | 31 | |
| 34 | 32 | /** |
| 35 | 33 | * The post type helper. |
| 36 | 34 | * |
| @@ -99,12 +97,12 @@ | ||
| 99 | 97 | |
| 100 | 98 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Function get_select_query returns a prepared query. |
| 101 | 99 | $post_ids = $this->wpdb->get_col( $query ); |
| 102 | 100 | |
| 103 | - $indexables = []; | |
| 104 | - foreach ( $post_ids as $post_id ) { | |
| 105 | - $indexables[] = $this->repository->find_by_id_and_type( (int) $post_id, 'post' ); | |
| 106 | - } | |
| 101 | + $indexables = $this->repository->find_by_multiple_ids_and_type( | |
| 102 | + \array_map( 'intval', $post_ids ), | |
| 103 | + 'post', | |
| 104 | + ); | |
| 107 | 105 | |
| 108 | 106 | if ( \count( $indexables ) > 0 ) { |
| 109 | 107 | \delete_transient( static::UNINDEXED_COUNT_TRANSIENT ); |
| 110 | 108 | \delete_transient( static::UNINDEXED_LIMITED_COUNT_TRANSIENT ); |
| @@ -121,9 +119,9 @@ | ||
| 121 | 119 | public function get_limit() { |
| 122 | 120 | /** |
| 123 | 121 | * Filter 'wpseo_post_indexation_limit' - Allow filtering the amount of posts indexed during each indexing pass. |
| 124 | 122 | * |
| 125 | - * @api int The maximum number of posts indexed. | |
| 123 | + * @param int $limit The maximum number of posts indexed. | |
| 126 | 124 | */ |
| 127 | 125 | $limit = \apply_filters( 'wpseo_post_indexation_limit', 25 ); |
| 128 | 126 | |
| 129 | 127 | if ( ! \is_int( $limit ) || $limit < 1 ) { |
| @@ -140,13 +138,13 @@ | ||
| 140 | 138 | */ |
| 141 | 139 | protected function get_count_query() { |
| 142 | 140 | $indexable_table = Model::get_table_name( 'Indexable' ); |
| 143 | 141 | |
| 144 | - $post_types = $this->get_post_types(); | |
| 142 | + $post_types = $this->post_type_helper->get_indexable_post_types(); | |
| 145 | 143 | $excluded_post_statuses = $this->post_helper->get_excluded_post_statuses(); |
| 146 | 144 | $replacements = \array_merge( |
| 147 | 145 | $post_types, |
| 148 | - $excluded_post_statuses | |
| 146 | + $excluded_post_statuses, | |
| 149 | 147 | ); |
| 150 | 148 | |
| 151 | 149 | $replacements[] = $this->version; |
| 152 | 150 | |
| @@ -157,13 +155,14 @@ | ||
| 157 | 155 | SELECT COUNT(P.ID) |
| 158 | 156 | FROM {$this->wpdb->posts} AS P |
| 159 | 157 | WHERE P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $post_types ), '%s' ) ) . ') |
| 160 | 158 | AND P.post_status NOT IN (' . \implode( ', ', \array_fill( 0, \count( $excluded_post_statuses ), '%s' ) ) . ") |
| 161 | - AND P.ID not in ( | |
| 162 | - SELECT I.object_id from $indexable_table as I | |
| 163 | - WHERE I.object_type = 'post' | |
| 159 | + AND NOT EXISTS ( | |
| 160 | + SELECT 1 FROM $indexable_table AS I | |
| 161 | + WHERE I.object_id = P.ID | |
| 162 | + AND I.object_type = 'post' | |
| 164 | 163 | AND I.version = %d )", |
| 165 | - $replacements | |
| 164 | + $replacements, | |
| 166 | 165 | ); |
| 167 | 166 | } |
| 168 | 167 | |
| 169 | 168 | /** |
| @@ -175,13 +174,13 @@ | ||
| 175 | 174 | */ |
| 176 | 175 | protected function get_select_query( $limit = false ) { |
| 177 | 176 | $indexable_table = Model::get_table_name( 'Indexable' ); |
| 178 | 177 | |
| 179 | - $post_types = $this->get_post_types(); | |
| 178 | + $post_types = $this->post_type_helper->get_indexable_post_types(); | |
| 180 | 179 | $excluded_post_statuses = $this->post_helper->get_excluded_post_statuses(); |
| 181 | 180 | $replacements = \array_merge( |
| 182 | 181 | $post_types, |
| 183 | - $excluded_post_statuses | |
| 182 | + $excluded_post_statuses, | |
| 184 | 183 | ); |
| 185 | 184 | $replacements[] = $this->version; |
| 186 | 185 | |
| 187 | 186 | $limit_query = ''; |
| @@ -197,26 +196,14 @@ | ||
| 197 | 196 | SELECT P.ID |
| 198 | 197 | FROM {$this->wpdb->posts} AS P |
| 199 | 198 | WHERE P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $post_types ), '%s' ) ) . ') |
| 200 | 199 | AND P.post_status NOT IN (' . \implode( ', ', \array_fill( 0, \count( $excluded_post_statuses ), '%s' ) ) . ") |
| 201 | - AND P.ID not in ( | |
| 202 | - SELECT I.object_id from $indexable_table as I | |
| 203 | - WHERE I.object_type = 'post' | |
| 200 | + AND NOT EXISTS ( | |
| 201 | + SELECT 1 FROM $indexable_table AS I | |
| 202 | + WHERE I.object_id = P.ID | |
| 203 | + AND I.object_type = 'post' | |
| 204 | 204 | AND I.version = %d ) |
| 205 | 205 | $limit_query", |
| 206 | - $replacements | |
| 206 | + $replacements, | |
| 207 | 207 | ); |
| 208 | - } | |
| 209 | - | |
| 210 | - /** | |
| 211 | - * Returns the post types that should be indexed. | |
| 212 | - * | |
| 213 | - * @return array The post types that should be indexed. | |
| 214 | - */ | |
| 215 | - protected function get_post_types() { | |
| 216 | - $public_post_types = $this->post_type_helper->get_public_post_types(); | |
| 217 | - $excluded_post_types = $this->post_type_helper->get_excluded_post_types_for_indexables(); | |
| 218 | - | |
| 219 | - // `array_values`, to make sure that the keys are reset. | |
| 220 | - return \array_values( \array_diff( $public_post_types, $excluded_post_types ) ); | |
| 221 | 208 | } |
| 222 | 209 | } |