Skip to content

Fix Orders & Transactions timing out before the 11.0.0 database update finishes - #3490

Merged
brianhogg merged 2 commits into
devfrom
fix/orders-months-pending-update
Nov 16, 2026
Merged

brianhogg merged 2 commits into
devfrom
fix/orders-months-pending-update

Conversation

@brianhogg

@brianhogg brianhogg commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

HS-282689

Description

The All Dates filter on Orders & Transactions lists the months that have rows in the table. LLMS_Table_Orders_Transactions::get_available_months() builds that list and leaves out orders that have a transaction, because the table shows those as transaction rows instead.

Until the 11.0.0 database update finishes its _llms_has_transaction backfill (lifterlms_db_version < 11.0.0), the method excludes those orders with p.ID NOT IN ( SELECT meta_value FROM wp_postmeta WHERE meta_key = '_llms_order_id' ). MariaDB runs that as a dependent subquery for every order and transaction row, so on a large store the Orders & Transactions page doesn't load until the update finishes. On sites behind Cloudflare it fails with Error 524.

The main table query in the same state already avoids this. It loads the order IDs once with get_order_ids_with_transactions() (cached) and passes them as post__not_in. The month query now reuses that list. After the update finishes, nothing changes: the flag-based query is used as before.

Fixes #3488

How has this been tested?

On MariaDB 11.4 with a synthetic dataset (16,000 orders, 22,000 transactions, 200,000 other posts, about 2.8 million postmeta rows):

Query Time
Month list, pre-update path, before this change over 120 s (stopped at max_statement_time)
Month list, pre-update path, with this change 0.2 s
Main table query, pre-update path (unchanged) 0.2 s

To check the result is the same, both queries ran on a smaller dataset where the original finishes: 2,000 orders and 2,500 transactions with mixed trash, auto-draft, and normal statuses, some trashed orders, and transactions pointing at a subset of orders. Both returned the same 182 months. Without the exclusion there are 199, so the comparison covers excluded orders.

The existing test_available_months_excludes_orders_with_transactions test runs on the post-update path; PHPUnit wasn't run locally and will run in CI. php -l and PHPCS (phpcs.xml) pass on the changed file.

Screenshots

N/A

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • This PR requires and contains at least one changelog file.
  • My code has been tested.
  • My code passes all existing automated tests.
  • My code follows the LifterLMS Coding & Documentation Standards.

Before the 11.0.0 _llms_has_transaction backfill finishes, the month list
excluded orders with transactions through an ID NOT IN ( SELECT ... ) subquery
that runs once per order. Reuse the cached order ID list the main query already uses.

Fixes #3488

Amp-Thread-ID: https://ampcode.com/threads/T-01a1e448-7786-70b5-85e1-0b6cbb96299b
Co-authored-by: brianhogg <brian@brianhogg.com>
@brianhogg brianhogg moved this to Awaiting Review in Development Nov 16, 2026
@brianhogg brianhogg moved this from Awaiting Review to Review in Progress in Development Nov 16, 2026
Avoids interpolating a built SQL clause, which plugin checkers flag. The order
IDs become %d placeholders; an empty list uses ID 0, which matches no post.

Refs #3488

Amp-Thread-ID: https://ampcode.com/threads/T-01a1e448-7786-70b5-85e1-0b6cbb96299b
Co-authored-by: brianhogg <brian@brianhogg.com>
@brianhogg
brianhogg merged commit fc3503c into dev Nov 16, 2026
16 checks passed
@brianhogg
brianhogg deleted the fix/orders-months-pending-update branch November 16, 2026 19:34
@github-project-automation github-project-automation Bot moved this from Review in Progress to Done in Development Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants