woocommerce / wc-smooth-generator

Smooth product, customer and order generation for WooCommerce
309 stars 49 forks source link

Switch Admin UI to generating in batches, using WC's BatchProcessor tool #136

Closed coreymckrill closed 4 months ago

coreymckrill commented 4 months ago

Changes proposed in this Pull Request:

This changes the approach to generating stuff used in the admin UI. Instead of creating a separate Action Scheduler event for every product or order that should get generated, it leverages the batch methods introduced in #125 (and refined by subsequent PRs) to generate batches of items in one event. It also makes use of WooCommerce's BatchProcessor tool to handle batch management when more than one batch is needed (if you want to generate hundreds of products, for example).

To go along with this improved background generation process, this makes some improvements to the UI on the Smooth Generator page in WP Admin. It adds a progress bar while a generation job is running, which is updated periodically via WP's heartbeat system. Plus some other miscellaneous tweaks to improve the UX of the page.

Fixes #121

How to test the changes in this Pull Request:

  1. Navigate to Tools > Smooth Generator. Click one of the buttons to generate either 10 products or 10 orders. The page should reload and now show you a progress bar in its indeterminate mode. The "Generate" buttons on the page should now be disabled, and the "Cancel" button should be enabled. It may take a minute or two before the Action Scheduler job starts running in the background, but then the bar should change to show the job is complete. Watch the music video while you wait (if you end up with Michael Jackson's Smooth Criminal video, I'm sorry it's so weird). When the job is complete, the buttons should toggle so that "Generate" is enabled again, and "Cancel" is disabled.
  2. Now try doing a much larger batch so that you will actually get to see a partially filled progress bar. Try generating something like 1,000 products. It might take a minute or two once again to get started, but then you should see a partially filled progress bar. It shouldn't take too much longer after that to complete, since it will be doing batches of 100 at a time.
  3. Initiate another generation job, and cancel it. Go to Tools > Scheduled Actions and make sure the event really is gone.

Changelog entry

Improve background generation tasks initiated through the WP Admin UI.

coreymckrill commented 4 months ago

I found that generating a lot of products was bottle-necked by the slew of woocommerce_run_product_attribute_lookup_update_callback jobs that were consequently created. Perhaps this will be addressed by other work in progress for WC Core, however.

🤔 I wonder if it would be worth disabling that lookup table altogether when we start a product generation process. And then re-enabling it afterward? Maybe that would cause other issues? I guess maybe it would depend on what kind of testing you were planning to do with the products...

If I generate a set of products, then that control is disabled while product generation is in progress ... but the order generation button is also enabled. I'm not sure if this is deliberate, but I do think it could be handy for users to be able to set both in motion (whether or not the work happens concurrently, it would save them from having to remember to check back in and trigger the second piece of work).

I think you mean the order generation button is also disabled? That's how it should be anyhow. Yeah, having multiple concurrent generation background tasks would probably be a nice enhancement, especially since you can already kind of do that with the CLI. Maybe something we could look at doing during #120

barryhughes commented 4 months ago

I wonder if it would be worth disabling that lookup table altogether when we start a product generation process. And then re-enabling it afterward? Maybe that would cause other issues?

The same train of thoughts was going through my head. I'm not really sure what's best. Also not directly related to this work, so 🤷🏼

barryhughes commented 4 months ago

I think you mean the order generation button is also disabled?

It's Friday and I can no longer type correctly, but yes. Thank you for logging it!