woocommerce / wc-smooth-generator

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

[Enhacement]: Improve getting a random user #79

Closed ovidiul closed 2 years ago

ovidiul commented 2 years ago

All Submissions:

Changes proposed in this Pull Request:

Closes #78 .

This PR will simply replace the expensive query generated by the ORDER BY rand() LIMIT 1 and instead, it computes the offset from the user's tables and uses that along with wp_rand to get a record using the LIMIT offset, 1 query which proves to be less expensive on sites with a large number of users.

How to test the changes in this Pull Request:

  1. merge the PR
  2. ideally, a large set of over 100K records in wp_users table should exist
  3. measure the time for time wp wc generate orders 10 before and after the change

Other information:

Changelog entry

Improves order generate for sites that have a large user base.

FOR PR REVIEWER ONLY: