Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelogs/orders-transactions-months-timeout.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
significance: patch
type: fixed
entry: "Fixed the Orders & Transactions screen timing out on large stores while the 11.0.0 database update is still pending."
Original file line number Diff line number Diff line change
Expand Up @@ -1276,12 +1276,20 @@ private function get_available_months() {
ORDER BY year DESC, month DESC"
);
} else {
$months = $wpdb->get_results(
"SELECT DISTINCT YEAR( p.post_date ) AS year, MONTH( p.post_date ) AS month
FROM {$wpdb->posts} AS p
WHERE p.post_status NOT IN ( 'auto-draft', 'trash' )
AND ( p.post_type = 'llms_transaction' OR ( p.post_type = 'llms_order' AND p.ID NOT IN ( SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_llms_order_id' ) ) )
ORDER BY year DESC, month DESC"
// An `ID NOT IN ( SELECT meta_value ... )` subquery runs once per order and takes minutes on
// large stores, so exclude the already-resolved list of order IDs instead.
// With no such orders, exclude ID 0, which matches no post, so the list always has a placeholder.
$orders_with_txns = $this->get_order_ids_with_transactions();
$orders_with_txns = $orders_with_txns ? $orders_with_txns : array( 0 );
$months = $wpdb->get_results(
$wpdb->prepare(
"SELECT DISTINCT YEAR( p.post_date ) AS year, MONTH( p.post_date ) AS month
FROM {$wpdb->posts} AS p
WHERE p.post_status NOT IN ( 'auto-draft', 'trash' )
AND ( p.post_type = 'llms_transaction' OR ( p.post_type = 'llms_order' AND p.ID NOT IN ( " . implode( ',', array_fill( 0, count( $orders_with_txns ), '%d' ) ) . ' ) ) )
ORDER BY year DESC, month DESC',
$orders_with_txns
)
);
}
wp_cache_set( $cache_key, $months, self::CACHE_GROUP, HOUR_IN_SECONDS );
Expand Down
Loading