| @@ -412,8 +412,18 @@ | ||
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | $indexables_to_create = \array_diff( $object_ids, $indexables_available ); |
| 415 | 415 | |
| 416 | + if ( ! empty( $indexables_to_create ) ) { | |
| 417 | + // Warm the object caches for the whole batch, so each build below does not trigger its own uncached queries. | |
| 418 | + if ( $object_type === 'post' ) { | |
| 419 | + \_prime_post_caches( $indexables_to_create ); | |
| 420 | + } | |
| 421 | + elseif ( $object_type === 'term' ) { | |
| 422 | + \_prime_term_caches( $indexables_to_create ); | |
| 423 | + } | |
| 424 | + } | |
| 425 | + | |
| 416 | 426 | foreach ( $indexables_to_create as $indexable_to_create ) { |
| 417 | 427 | $indexables[] = $this->builder->build_for_id_and_type( $indexable_to_create, $object_type ); |
| 418 | 428 | } |
| 419 | 429 | } |