From 72c93e8133e4c11e2dde3f40c7a4bf30c5da826d Mon Sep 17 00:00:00 2001 From: zaydiscold <21329260+zaydiscold@users.noreply.github.com> Date: Mon, 8 Jun 2026 16:52:07 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Avoid=20redundant=20DB=20qu?= =?UTF-8?q?ery=20in=20Traffic=20Dashboard=20poll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- .jules/bolt.md | 3 +++ server/controllers/PoolController.js | 11 +++-------- 2 files changed, 6 insertions(+), 8 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..a94bc51 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2026-06-08 - [Avoid Re-Querying Static DB Data if Cache Exists] +**Learning:** In applications using frequent polling (like a live traffic dashboard), direct database queries for static or slow-changing data (like model catalogs/prices) can cause unnecessary DB load. The application already maintained an in-memory cache for models `getCachedPoolModels()`, but `getTraffic` was directly querying the DB using `prisma.cachedModel.findMany` instead of utilizing the cache. +**Action:** Always check if a caching layer or service already exists for lookup/reference data before writing direct database queries, especially on high-frequency endpoints. diff --git a/server/controllers/PoolController.js b/server/controllers/PoolController.js index 36a9884..dd0f71b 100644 --- a/server/controllers/PoolController.js +++ b/server/controllers/PoolController.js @@ -469,6 +469,8 @@ class PoolController extends BaseController { const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000); // Fetch latest 100 requests for the log table + // ⚡ Bolt: Use existing cached model fetch rather than re-querying the DB + // on every traffic dashboard poll. const [rawLogs, metrics, modelPrices, routing] = await Promise.all([ prisma.requestLog.findMany({ take: 100, @@ -496,14 +498,7 @@ class PoolController extends BaseController { where: { createdAt: { gte: oneDayAgo } }, _count: { id: true }, }), - prisma.cachedModel.findMany({ - select: { - id: true, - promptPrice: true, - completionPrice: true, - requestPrice: true, - }, - }), + modelCatalog.getCachedPoolModels(), rotationManager.getStatusAsync(), ]); const pricesByModel = new Map(modelPrices.map((model) => [model.id, model]));