Skip to content

Commit d98de9b

Browse files
committed
Time the loading of cached events
1 parent 7b537d2 commit d98de9b

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import cookieSession from 'cookie-session';
2020
import {initRoutes} from './routes';
2121
import {ensureCachedSheetDataTableExists} from './init-dependencies/google/ensure-cached-sheet-data-table-exists';
2222
import {loadCachedSheetData} from './load-cached-sheet-data';
23+
import {timeAsync} from './util';
2324

2425
// Dependencies and Config
2526
const conf = loadConfig();
@@ -95,12 +96,18 @@ void (async () => {
9596
)();
9697

9798
deps.logger.info('Loading cached external events...');
98-
await loadCachedSheetData(
99-
deps.getCachedSheetData,
100-
deps.logger,
101-
deps.sharedReadModel.updateState
99+
await timeAsync(elapsedNs =>
100+
deps.logger.info(
101+
'Loaded cached external events in %sms',
102+
elapsedNs / (1000 * 1000)
103+
)
104+
)(
105+
loadCachedSheetData(
106+
deps.getCachedSheetData,
107+
deps.logger,
108+
deps.sharedReadModel.updateState
109+
)
102110
);
103-
deps.logger.info('Cached external events loaded');
104111
await deps.sharedReadModel.asyncRefresh()();
105112
await deps.sharedReadModel.asyncApplyExternalEventSources()();
106113

src/util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,12 @@ export const fieldIsUUID =
6464
obj: T
6565
): obj is T & {[P in K]: tt.UUID} =>
6666
E.isRight(tt.UUID.decode(obj[key]));
67+
68+
export const timeAsync =
69+
(callback: (nanoseconds: number) => void) => async (fn: Promise<void>) => {
70+
const start = process.hrtime.bigint();
71+
const result = await fn;
72+
// Realistically we aren't going to be have elapsed periods big enough that this conversion back to number is problematic.
73+
callback(Number(process.hrtime.bigint() - start));
74+
return result;
75+
};

0 commit comments

Comments
 (0)