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]));