fix: performance hardening — eliminate full table scans (#9)
Inventory: - /issues: replaced full scan + client filter with NocoDB server-side WHERE filter (Received eq Issues/Issue). Single query, ~200 rows max. - /needs-review-count: replaced full scan with server-side WHERE + limit=1 + pageInfo.totalRows. Returns count without fetching data. Budget: - buildLookups(): added 2-minute cache for payee/account/category maps. Eliminates 3 API calls per request for repeated queries. - /summary cache (added earlier): 1-minute TTL still active. Files: services/inventory/server.js, services/budget/server.js
This commit is contained in:
@@ -102,8 +102,12 @@ function currentMonth() {
|
||||
return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
/** Build lookup maps for payees, accounts, and categories. */
|
||||
/** Build lookup maps for payees, accounts, and categories (cached 2 min). */
|
||||
let _lookupsCache = { data: null, expiresAt: 0 };
|
||||
async function buildLookups() {
|
||||
if (_lookupsCache.data && Date.now() < _lookupsCache.expiresAt) {
|
||||
return _lookupsCache.data;
|
||||
}
|
||||
const [payees, accounts, categories] = await Promise.all([
|
||||
api.getPayees(),
|
||||
api.getAccounts(),
|
||||
@@ -115,7 +119,9 @@ async function buildLookups() {
|
||||
for (const a of accounts) accountMap[a.id] = a.name;
|
||||
const categoryMap = {};
|
||||
for (const c of categories) categoryMap[c.id] = c.name;
|
||||
return { payeeMap, accountMap, categoryMap };
|
||||
const result = { payeeMap, accountMap, categoryMap };
|
||||
_lookupsCache = { data: result, expiresAt: Date.now() + 120000 };
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Enrich a transaction with resolved names. */
|
||||
|
||||
Reference in New Issue
Block a user