Speed up the dashboard's Hardware not on assets count and the invoices list's hardware filter: productHardwarePending and the hardware filter in agent/invoices.php had a COUNT(*) subquery a line on assets by the line's invoice and line, and where nearly every asset has asset_invoice_id 0 the index statistics say a lookup finds every asset, so the database read the whole assets table once a hardware line, 1.89 seconds and 3.1 million rows on a forum install and 22.9 seconds and 185 million rows on a test install with 25,000 assets none from an invoice; both now count each line's assets once and join them through the new productHardwareMadeJoinSql, a LEFT JOIN onto invoice_items of assets with asset_invoice_id > 0 grouped by invoice and line, a range the database measures on the index itself, with productHardwareShortSql comparing against hardware_made.made; run with none, 3,000 and 21,000 of 25,000 assets made from an invoice, the same counts as before each time and 18 to 32 ms; the lookups by one invoice give the database a constant and are unchanged; add both to the 26.11.8 changelog section

This commit is contained in:
johnnyq
2026-11-13 12:18:21 -05:00
parent d14788a4f1
commit 20cc3a9cf3
3 changed files with 36 additions and 13 deletions

View File

@@ -52,7 +52,7 @@ $recurring_filter_row = $recurring_filter ? billingRow('recurring', $recurring_f
// Hardware sold on them that isn't on the client's assets yet (functions/products.php)
$hardware_filter = !empty($_GET['hardware']);
$hardware_query = $hardware_filter ? "AND " . productHardwareInvoiceSql() . " AND invoices.invoice_id IN (SELECT invoice_items.item_invoice_id FROM invoice_items
JOIN products ON products.product_id = invoice_items.item_product_id WHERE " . productHardwareShortSql() . ")" : '';
JOIN products ON products.product_id = invoice_items.item_product_id " . productHardwareMadeJoinSql() . " WHERE " . productHardwareShortSql() . ")" : '';
// Category Filter
$category_filter = intval($_GET['category'] ?? 0);