Product Filters > Fix Performance issue and Fatal error on stores with a high volume of products (https://github.com/woocommerce/woocommerce-blocks/pull/10198)

* Remove queries that fetch all products for manipulating the results returned by the Store API for certain use-cases.

* Keep support for Product Collection block
This commit is contained in:
Patricia Hillebrandt 2023-07-14 10:34:55 +02:00 committed by GitHub
parent 3d8331363c
commit 53668eb066
2 changed files with 0 additions and 41 deletions

View File

@ -141,19 +141,6 @@ class ProductCollection extends AbstractBlock {
* which is a server-side rendered (SSR) block, retrieves the products that match the filters.
*/
$this->asset_data_registry->add( 'is_rendering_php_template', true, true );
$frontend_query = $this->get_final_frontend_query( $parsed_block['attrs']['query'], null, true );
// Override the query to get all products.
$fields_to_override = [
'posts_per_page' => -1,
'paged' => null,
];
$new_array = array_merge( $frontend_query, $fields_to_override );
$products = new \WP_Query( $new_array );
$product_ids = wp_list_pluck( $products->posts, 'ID' );
// Add the product ids to the asset data registry, so that filter blocks can use it.
$this->asset_data_registry->add( 'product_ids', $product_ids, true );
}
/**

View File

@ -157,7 +157,6 @@ class ProductQuery extends AbstractBlock {
// Set this so that our product filters can detect if it's a PHP template.
$this->asset_data_registry->add( 'has_filterable_products', true, true );
$this->asset_data_registry->add( 'is_rendering_php_template', true, true );
$this->asset_data_registry->add( 'product_ids', $this->get_products_ids_by_attributes( $parsed_block ), true );
add_filter(
'query_loop_block_query_vars',
array( $this, 'build_query' ),
@ -246,33 +245,6 @@ class ProductQuery extends AbstractBlock {
return $this->filter_query_to_only_include_ids( $merged_query, $handpicked_products );
}
/**
* Return the product ids based on the attributes and global query.
* This is used to allow the filter blocks to render data that matches with variations. More details here: https://github.com/woocommerce/woocommerce-blocks/issues/7245
*
* @param array $parsed_block The block being rendered.
* @return array
*/
private function get_products_ids_by_attributes( $parsed_block ) {
$query = $this->merge_queries(
array(
'post_type' => 'product',
'post__in' => array(),
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(),
'tax_query' => array(),
),
$this->get_queries_by_custom_attributes( $parsed_block ),
$this->get_global_query( $parsed_block )
);
$products = new \WP_Query( $query );
$post_ids = wp_list_pluck( $products->posts, 'ID' );
return $post_ids;
}
/**
* Merge in the first parameter the keys "post_in", "meta_query" and "tax_query" of the second parameter.
*