[Store Customization] Flush permalinks after updating all products (https://github.com/woocommerce/woocommerce-blocks/pull/11971)

* Flush after updating all products, not after updating each of the products

Flushing is an expensive operation so we should run it carefully

* Remove the index param and add the last_product param to the Product endpoint.

---------

Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
This commit is contained in:
Alba Rincón 2023-12-01 16:59:09 +01:00 committed by GitHub
parent 8f99863a2e
commit ce71e30732
2 changed files with 10 additions and 5 deletions

View File

@ -260,7 +260,6 @@ class ProductUpdater {
),
)
);
flush_rewrite_rules();
require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/file.php';

View File

@ -46,14 +46,14 @@ class Product extends AbstractRoute {
'callback' => [ $this, 'get_response' ],
'permission_callback' => [ Middleware::class, 'is_authorized' ],
'args' => [
'index' => [
'description' => __( 'The business description for a given store.', 'woo-gutenberg-products-block' ),
'type' => 'integer',
],
'products_information' => [
'description' => __( 'Data generated by AI for updating dummy products.', 'woo-gutenberg-products-block' ),
'type' => 'object',
],
'last_product' => [
'description' => __( 'Whether the product being updated is the last one in the loop', 'woo-gutenberg-products-block' ),
'type' => 'boolean',
],
],
],
'schema' => [ $this->schema, 'get_public_item_schema' ],
@ -82,6 +82,12 @@ class Product extends AbstractRoute {
$product_updater->update_product_content( $product_information );
$last_product_to_update = $request['last_product'] ?? false;
if ( $last_product_to_update ) {
flush_rewrite_rules();
}
return rest_ensure_response(
array(
'ai_content_generated' => true,