Speed up the dashboard and the menu counts on installs with years of history: database 3.6.4 adds seven indexes, each only where it is missing and also in db.sql for new installs - tickets on ticket_resolved_at, ticket_closed_at and ticket_created_at, a five-column one led by ticket_billable that answers the unbilled count from the index alone, ticket_replies on ticket_reply_by with ticket_reply_created_at, invoices on invoice_status and expenses on expense_date - so open tickets, unpaid invoices, an agent time this week and unbilled tickets are found directly, where each was a read of the whole table, a dozen times over tickets on the dashboard and twice in the menu on every page; dashboardPeriodOptions finds the years with data with one index step a year per table in place of a UNION of YEAR over every row of five tables, and dashboardLatestIncome joins from payments with STRAIGHT_JOIN so the last five are read off payment_date, where every payment was sorted; measured on 280,000 tickets, 380,000 replies and 70,000 invoices the dashboard went from 5.1s to 0.7s and other pages lost about half a second, with every figure unchanged; also fix lists past 10,000 pages, where includes/filter_footer.php left the pager step unset and a division by zero ended the page at its page numbers; add a 26.11.7 changelog section

This commit is contained in:
johnnyq
2026-11-11 14:13:11 -05:00
parent 914d1c549a
commit 5ba8ffc0cf
5 changed files with 145 additions and 24 deletions

15
db.sql
View File

@@ -1751,7 +1751,8 @@ CREATE TABLE `expenses` (
KEY `expense_import_key` (`expense_import_key`),
KEY `expense_reimbursement_id` (`expense_reimbursement_id`),
KEY `expense_reconciliation_id` (`expense_reconciliation_id`),
KEY `expense_refund_of_id` (`expense_refund_of_id`)
KEY `expense_refund_of_id` (`expense_refund_of_id`),
KEY `expense_date` (`expense_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -1901,7 +1902,8 @@ CREATE TABLE `invoices` (
`invoice_quote_id` int(11) NOT NULL DEFAULT 0,
`invoice_client_id` int(11) NOT NULL,
PRIMARY KEY (`invoice_id`),
KEY `invoice_client_id` (`invoice_client_id`)
KEY `invoice_client_id` (`invoice_client_id`),
KEY `invoice_status` (`invoice_status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -3920,7 +3922,8 @@ CREATE TABLE `ticket_replies` (
`ticket_reply_by` int(11) NOT NULL,
`ticket_reply_ticket_id` int(11) NOT NULL,
PRIMARY KEY (`ticket_reply_id`),
KEY `ticket_reply_ticket_id` (`ticket_reply_ticket_id`,`ticket_reply_archived_at`)
KEY `ticket_reply_ticket_id` (`ticket_reply_ticket_id`,`ticket_reply_archived_at`),
KEY `ticket_reply_by` (`ticket_reply_by`,`ticket_reply_created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -4156,7 +4159,11 @@ CREATE TABLE `tickets` (
KEY `ticket_resolution_due_at` (`ticket_resolution_due_at`),
KEY `ticket_client_id` (`ticket_client_id`,`ticket_archived_at`),
KEY `ticket_project_id` (`ticket_project_id`),
KEY `ticket_template_id` (`ticket_template_id`)
KEY `ticket_template_id` (`ticket_template_id`),
KEY `ticket_resolved_at` (`ticket_resolved_at`),
KEY `ticket_closed_at` (`ticket_closed_at`),
KEY `ticket_created_at` (`ticket_created_at`),
KEY `ticket_billable` (`ticket_billable`,`ticket_invoice_id`,`ticket_status`,`ticket_client_id`,`ticket_archived_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;