| @@ -11,9 +11,9 @@ | ||
| 11 | 11 | declare (strict_types=1); |
| 12 | 12 | namespace WindPress\WindPress\Integration\Elementor; |
| 13 | 13 | |
| 14 | 14 | use Elementor\Plugin; |
| 15 | -use WP_Query; | |
| 15 | +use WindPress\WindPress\Core\Scanner\PostQuery; | |
| 16 | 16 | /** |
| 17 | 17 | * @author Joshua Gugun Siagian <suabahasa@gmail.com> |
| 18 | 18 | */ |
| 19 | 19 | class Compile |
| @@ -33,13 +33,11 @@ | ||
| 33 | 33 | { |
| 34 | 34 | $contents = []; |
| 35 | 35 | $post_types = get_option('elementor_cpt_support', Plugin::ELEMENTOR_DEFAULT_POST_TYPES); |
| 36 | 36 | $post_types = apply_filters('f!windpress/integration/elementor/compile:get_contents.post_types', $post_types); |
| 37 | - $next_batch = $metadata['next_batch'] !== \false ? $metadata['next_batch'] : 1; | |
| 38 | - $per_page = apply_filters('f!windpress/integration/elementor/compile:get_contents.post_per_page', (int) get_option('posts_per_page', 20)); | |
| 39 | - $wpQuery = new WP_Query([ | |
| 37 | + $per_page = apply_filters('f!windpress/integration/elementor/compile:get_contents.post_per_page', PostQuery::batch_size()); | |
| 38 | + $scan = new PostQuery([ | |
| 40 | 39 | 'posts_per_page' => $per_page, |
| 41 | - 'paged' => $next_batch, | |
| 42 | 40 | 'fields' => 'ids', |
| 43 | 41 | 'post_type' => $post_types, |
| 44 | 42 | 'post_status' => get_post_stati(), |
| 45 | 43 | 'no_found_rows' => \true, |
| @@ -47,9 +45,10 @@ | ||
| 47 | 45 | 'update_post_term_cache' => \false, |
| 48 | 46 | 'ignore_sticky_posts' => \true, |
| 49 | 47 | // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- This only run by trigger on specific event |
| 50 | 48 | 'meta_query' => array_merge(['relation' => 'OR'], array_map(static fn($key) => ['key' => $key], $this->post_meta_keys)), |
| 51 | - ]); | |
| 49 | + ], $metadata); | |
| 50 | + $wpQuery = $scan->query; | |
| 52 | 51 | if ($wpQuery->posts !== []) { |
| 53 | 52 | update_meta_cache('post', $wpQuery->posts); |
| 54 | 53 | } |
| 55 | 54 | foreach ($wpQuery->posts as $post_id) { |
| @@ -56,11 +55,9 @@ | ||
| 56 | 55 | foreach ($this->get_post_metas($post_id) as $content) { |
| 57 | 56 | $contents[] = $content; |
| 58 | 57 | } |
| 59 | 58 | } |
| 60 | - $post_count = count($wpQuery->posts); | |
| 61 | - $has_more = $per_page > 0 && $post_count === $per_page; | |
| 62 | - return ['metadata' => ['next_batch' => $has_more ? $next_batch + 1 : \false, 'total_batches' => \false], 'contents' => $contents]; | |
| 59 | + return ['metadata' => $scan->metadata(), 'contents' => $contents]; | |
| 63 | 60 | } |
| 64 | 61 | public function get_post_metas($post_id): array |
| 65 | 62 | { |
| 66 | 63 | $contents = []; |
| @@ -66,9 +63,9 @@ | ||
| 66 | 63 | $contents = []; |
| 67 | 64 | foreach ($this->post_meta_keys as $post_metum_key) { |
| 68 | 65 | $meta_value = get_post_meta($post_id, $post_metum_key, \true); |
| 69 | 66 | if ($meta_value) { |
| 70 | - $contents[] = ['name' => $post_id, 'content' => $meta_value, 'type' => 'json']; | |
| 67 | + $contents[] = ['source_id' => 'post:' . $post_id . ':meta:' . $post_metum_key, 'name' => $post_id, 'content' => $meta_value, 'type' => 'json']; | |
| 71 | 68 | } |
| 72 | 69 | } |
| 73 | 70 | return $contents; |
| 74 | 71 | } |