Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
[Store Customization] Flush permalinks after updating all products (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
albarin and nefeline authored Dec 1, 2023
1 parent 664c56f commit 4962e59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/Patterns/ProductUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ public function update_product_content( $ai_generated_product_content ) {
),
)
);
flush_rewrite_rules();

require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
Expand Down
14 changes: 10 additions & 4 deletions src/StoreApi/Routes/V1/AI/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public function get_args() {
'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' ],
Expand Down Expand Up @@ -82,6 +82,12 @@ protected function get_route_post_response( \WP_REST_Request $request ) {

$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,
Expand Down

0 comments on commit 4962e59

Please sign in to comment.