Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
OllieJones committed Aug 11, 2024
1 parent 44ae850 commit 0b66fe5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
21 changes: 14 additions & 7 deletions code/class-textdex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion fast-woo-order-lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion languages/fast-woo-order-lookup.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ The orders page itself contains a very slow query (to be fixed in Woocommerce 9.
<h4>Credits</h4>
Thanks to Leho Kraav for bringing this problem to my attention.

Thanks to Sebastian Sommer for using early versions of the plugin on a large store.

Thanks to Jetbrains for the use of their software development tools, especially [PhpStorm](https://www.jetbrains.com/phpstorm/). It's hard to imagine how a plugin like this one could be developed without PhpStorm's tools for exploring epic code bases like WordPress's.

<h4>How can I learn more about making my WordPress site more efficient?</h4>
Expand Down Expand Up @@ -82,15 +84,19 @@ Follow the usual procedure for installing a plugin from the wordpress.org plugin

== Upgrade Notice ==

A compatibiity issue with MariaDB 10.3 and earlier is fixed.

Initial indexing load now uses longer chunks.

Tnis plugin is now compatible with WooCommerce's updgrades to 9.0.0 and 8.9.3. And, it keeps a cache of custom field names for orders to avoid the very slow load time for order pages.

When you install this upgrade, the plugin repeats the indexing process to add some new fields.

== Changelog ==

= 1.1.0 August 7, 2024 =
= 1.1.0 August 11, 2024 =

* Some MariaDB / MySQL versions implicitly cast integers to latin1 strings.
* Some MariaDB / MySQL versions implicitly cast integers to latin1 strings causing problems. Explicit casting fixes the issue.

= 1.0.2 August 5, 2024 =

Expand Down

0 comments on commit 0b66fe5

Please sign in to comment.