diff --git a/app.js b/app.js index 54b294c9..705f5979 100644 --- a/app.js +++ b/app.js @@ -19,6 +19,7 @@ import routerLotOccupancies from './routes/lotOccupancies.js'; import routerWorkOrders from './routes/workOrders.js'; import routerReports from './routes/reports.js'; import routerAdmin from './routes/admin.js'; +import { preloadCaches } from './helpers/functions.cache.js'; import * as configFunctions from './helpers/functions.config.js'; import * as printFunctions from './helpers/functions.print.js'; import * as dateTimeFns from '@cityssm/utils-datetime'; @@ -32,6 +33,7 @@ import { useTestDatabases } from './data/databasePaths.js'; import Debug from 'debug'; const debug = Debug(`lot-occupancy-system:app:${process.pid}`); databaseInitializer.initializeDatabase(); +preloadCaches(); const _dirname = '.'; export const app = express(); app.disable('X-Powered-By'); diff --git a/app.ts b/app.ts index 22991d7b..97ef56e5 100644 --- a/app.ts +++ b/app.ts @@ -24,6 +24,8 @@ import routerWorkOrders from './routes/workOrders.js' import routerReports from './routes/reports.js' import routerAdmin from './routes/admin.js' +import { preloadCaches } from './helpers/functions.cache.js' + import * as configFunctions from './helpers/functions.config.js' import * as printFunctions from './helpers/functions.print.js' import * as dateTimeFns from '@cityssm/utils-datetime' @@ -48,6 +50,12 @@ const debug = Debug(`lot-occupancy-system:app:${process.pid}`) databaseInitializer.initializeDatabase() +/* + * PRELOAD CACHES + */ + +preloadCaches() + /* * INITIALIZE APP */ diff --git a/helpers/functions.cache.d.ts b/helpers/functions.cache.d.ts index 17bd15a7..a153ac1d 100644 --- a/helpers/functions.cache.d.ts +++ b/helpers/functions.cache.d.ts @@ -18,4 +18,5 @@ export declare function getWorkOrderTypeById(workOrderTypeId: number): Promise; export declare function getWorkOrderMilestoneTypeById(workOrderMilestoneTypeId: number): Promise; export declare function getWorkOrderMilestoneTypeByWorkOrderMilestoneType(workOrderMilestoneTypeString: string): Promise; +export declare function preloadCaches(): void; export declare function clearCacheByTableName(tableName: string, relayMessage?: boolean): void; diff --git a/helpers/functions.cache.js b/helpers/functions.cache.js index fa7d3ec6..aa1b12b8 100644 --- a/helpers/functions.cache.js +++ b/helpers/functions.cache.js @@ -160,6 +160,15 @@ export async function getWorkOrderMilestoneTypeByWorkOrderMilestoneType(workOrde workOrderMilestoneTypeLowerCase); }); } +export function preloadCaches() { + debug('Preloading caches'); + void getLotOccupantTypes(); + void getLotStatuses(); + void getLotTypes(); + void getOccupancyTypes(); + void getWorkOrderTypes(); + void getWorkOrderMilestoneTypes(); +} function clearWorkOrderMilestoneTypesCache() { workOrderMilestoneTypes = undefined; } diff --git a/helpers/functions.cache.ts b/helpers/functions.cache.ts index c1d40722..08b0ccc9 100644 --- a/helpers/functions.cache.ts +++ b/helpers/functions.cache.ts @@ -298,6 +298,16 @@ export async function getWorkOrderMilestoneTypeByWorkOrderMilestoneType( }) } +export function preloadCaches(): void { + debug('Preloading caches') + void getLotOccupantTypes() + void getLotStatuses() + void getLotTypes() + void getOccupancyTypes() + void getWorkOrderTypes() + void getWorkOrderMilestoneTypes() +} + function clearWorkOrderMilestoneTypesCache(): void { workOrderMilestoneTypes = undefined }