( adapter: SessionRuntimeAdapter, sessionId: string, timeRange: ContactsTimeRangeState, factsCache: ContactsFactsCacheContext | null, facts: ContactsSessionFacts, expectedDbVersion: string )
| 401 | } |
| 402 | |
| 403 | function writeSessionFacts( |
| 404 | adapter: SessionRuntimeAdapter, |
| 405 | sessionId: string, |
| 406 | timeRange: ContactsTimeRangeState, |
| 407 | factsCache: ContactsFactsCacheContext | null, |
| 408 | facts: ContactsSessionFacts, |
| 409 | expectedDbVersion: string |
| 410 | ): void { |
| 411 | if (!factsCache) return |
| 412 | const dbVersion = getSessionDbVersion(adapter, sessionId) |
| 413 | if (dbVersion !== expectedDbVersion) { |
| 414 | appLogger.debug('contacts', 'skipped contacts session facts cache write because db version changed', { |
| 415 | sessionId, |
| 416 | }) |
| 417 | return |
| 418 | } |
| 419 | writeCachedContactsSessionFacts( |
| 420 | sessionId, |
| 421 | factsCache.dir, |
| 422 | buildContactsSessionFactsCacheKey(CONTACTS_ALGORITHM_VERSION, timeRange), |
| 423 | dbVersion, |
| 424 | facts |
| 425 | ) |
| 426 | writeCachedContactsSessionLatest(sessionId, factsCache.dir, factsCache.latestKey, dbVersion, { |
| 427 | latestMessageTs: facts.latestMessageTs, |
| 428 | }) |
| 429 | factsCache.stats.writes += 2 |
| 430 | } |
| 431 | |
| 432 | function getSessionDbVersion(adapter: SessionRuntimeAdapter, sessionId: string): string { |
| 433 | return getDbFileVersion(adapter.getDbPath(sessionId)) |
no test coverage detected