From 1761f4194344b5124401a4d1935c42b09c71705e Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sun, 5 Apr 2026 12:39:24 -0400 Subject: [PATCH] Invalidate stats cache after any ticket-modifying API call StatsModel::invalidateCache() was never called from any API, so the 60s cached stats persisted after bulk assign/status/priority changes, ticket updates, assignments, and clones. Dashboard tiles showed stale counts until the TTL expired. Added invalidation to the four APIs that affect dashboard stat tiles: - bulk_operation.php: after successful bulk assign/status/priority - assign_ticket.php: after successful reassignment - update_ticket.php: after any successful ticket update - clone_ticket.php: after successful clone (open_tickets changes) Co-Authored-By: Claude Sonnet 4.6 --- api/assign_ticket.php | 2 ++ api/bulk_operation.php | 4 ++++ api/clone_ticket.php | 2 ++ api/update_ticket.php | 8 +++++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/api/assign_ticket.php b/api/assign_ticket.php index ad1fd6e..0b21348 100644 --- a/api/assign_ticket.php +++ b/api/assign_ticket.php @@ -84,5 +84,7 @@ if (!$success) { http_response_code(500); apiRespond(['success' => false, 'error' => 'Failed to update ticket assignment']); } else { + require_once dirname(__DIR__) . '/models/StatsModel.php'; + (new StatsModel($conn))->invalidateCache(); apiRespond(['success' => true]); } diff --git a/api/bulk_operation.php b/api/bulk_operation.php index 5c5b9f4..2783224 100644 --- a/api/bulk_operation.php +++ b/api/bulk_operation.php @@ -110,6 +110,10 @@ if (isset($result['error'])) { 'error' => $result['error'] ]); } else { + // Invalidate stats cache so dashboard tiles reflect changes immediately + require_once dirname(__DIR__) . '/models/StatsModel.php'; + (new StatsModel($conn))->invalidateCache(); + $message = "Bulk operation completed: {$result['processed']} succeeded, {$result['failed']} failed"; if ($inaccessibleCount > 0) { $message .= " ($inaccessibleCount skipped - no access)"; diff --git a/api/clone_ticket.php b/api/clone_ticket.php index 94710f0..ecb1969 100644 --- a/api/clone_ticket.php +++ b/api/clone_ticket.php @@ -111,6 +111,8 @@ try { $dependencyModel = new DependencyModel($conn); $dependencyModel->addDependency($result['ticket_id'], $sourceTicketId, 'relates_to', $userId); + require_once dirname(__DIR__) . '/models/StatsModel.php'; + (new StatsModel($conn))->invalidateCache(); echo json_encode([ 'success' => true, 'new_ticket_id' => $result['ticket_id'], diff --git a/api/update_ticket.php b/api/update_ticket.php index 9096cdb..ab82e17 100644 --- a/api/update_ticket.php +++ b/api/update_ticket.php @@ -270,7 +270,13 @@ try { // Discard any output that might have been generated ob_end_clean(); - + + // Invalidate stats cache on successful ticket update + if (!empty($result['success'])) { + require_once dirname(__DIR__) . '/models/StatsModel.php'; + (new StatsModel($conn))->invalidateCache(); + } + // Return response if (!empty($result['http_status'])) { http_response_code($result['http_status']);