diff --git a/code/class-textdex.php b/code/class-textdex.php index da19e0c..9be460f 100644 --- a/code/class-textdex.php +++ b/code/class-textdex.php @@ -18,14 +18,12 @@ class Textdex { /** @var int The maximum number of tuples per insert */ private $trigram_batch_size = 250; /** @var int The number of posts per metadata query batch. */ - private $batch_size = 100; + private $batch_size = 200; private $attempted_inserts = 0; private $actual_inserts = 0; private $alias_chars = 'abcdefghijklmnopqrstuvwxyz'; - /** @var int Number of seconds for each batch-loading action. */ - private $max_batch_duration = 25; public function __construct() { global $wpdb; @@ -74,7 +72,7 @@ public function activate() { $this->update_option( $textdex_status ); } $old_version = array_key_exists( 'version', $textdex_status ) ? $textdex_status['version'] : FAST_WOO_ORDER_LOOKUP_VERSION; - if ( -1 === version_compare( $old_version, FAST_WOO_ORDER_LOOKUP_VERSION) ) { + if ( - 1 === version_compare( $old_version, FAST_WOO_ORDER_LOOKUP_VERSION ) ) { if ( $this->new_minor_version( $old_version, FAST_WOO_ORDER_LOOKUP_VERSION ) ) { $this->get_order_id_range(); } @@ -103,10 +101,17 @@ public function load_textdex() { public function load_batch() { require_once( plugin_dir_path( __FILE__ ) . 'class-custom-fields.php' ); $start_time = time(); - $end_time = $start_time + $this->max_batch_duration; + /* Give ourselves max_execution_time -10 sec to run, unless max_execution_time is very short. */ + $max_time = ini_get( 'max_execution_time' ); + $safe_time = ( $max_time > 30 ) ? 10 : 2; + $end_time = $start_time + $max_time - $safe_time; + $end_time = ( $end_time > $start_time ) ? $end_time : $start_time + 1; + set_time_limit( $max_time ); + + /* Do the field name cache (this is idempotent) */ $cust = new Custom_Fields(); $cust->get_order_custom_field_names(); - $done = false; + $done = false; $another_batch = false; while ( ! $done ) { $another_batch = $this->load_next_batch(); @@ -119,7 +124,9 @@ public function load_batch() { $done = true; continue; } + set_time_limit( $max_time ); } + delete_transient( 'fast_woo_order_lookup_scheduled' ); if ( $another_batch ) { $this->schedule_batch(); } @@ -128,7 +135,7 @@ public function load_batch() { public function schedule_batch() { if ( $this->have_more_batches() ) { - as_enqueue_async_action( 'fast_woo_order_lookup_textdex_action', array(), 'fast_woo_order_lookup' ); + as_enqueue_async_action( 'fast_woo_order_lookup_textdex_action', array(), 'fast_woo_order_lookup' , true); } } diff --git a/fast-woo-order-lookup.php b/fast-woo-order-lookup.php index 5f2889c..452df1a 100644 --- a/fast-woo-order-lookup.php +++ b/fast-woo-order-lookup.php @@ -12,7 +12,7 @@ * Plugin URI: https://plumislandmedia.net/wordpress-plugins/fast-woo-order-lookup/ * Description: Look up orders faster in large WooCommerce stores with many orders. * Version: 1.1.0 - * Author: OllieJones + * Author: Ollie Jones * Author URI: https://github.com/OllieJones * Text Domain: fast-woo-order-lookup * Domain Path: /languages diff --git a/languages/fast-woo-order-lookup.pot b/languages/fast-woo-order-lookup.pot index 397ddcb..2f4009d 100644 --- a/languages/fast-woo-order-lookup.pot +++ b/languages/fast-woo-order-lookup.pot @@ -9,7 +9,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2024-08-07T15:47:36-04:00\n" +"POT-Creation-Date: 2024-08-11T06:30:30-04:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.9.0\n" "X-Domain: fast-woo-order-lookup\n" diff --git a/readme.txt b/readme.txt index 919bfbe..e929050 100644 --- a/readme.txt +++ b/readme.txt @@ -29,6 +29,8 @@ The orders page itself contains a very slow query (to be fixed in Woocommerce 9.