Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 3 additions & 8 deletions server/controllers/PoolController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]));
Expand Down
Loading