Skip to content

Commit bfb48cc

Browse files
committed
#134 re-fetch case summary if version is outdated
1 parent db679b3 commit bfb48cc

2 files changed

Lines changed: 31 additions & 13 deletions

File tree

serverless/lib/CaseProcessor.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import axios from 'axios';
1010
import { wrapper } from 'axios-cookiejar-support';
1111
import * as cheerio from 'cheerio';
1212

13+
// Version date used to determine whether a cached 'complete' CaseSummary is
14+
// up-to-date or should be re-fetched to align with current schema/logic.
15+
export const CASE_SUMMARY_VERSION_DATE = new Date('2025-10-06T00:00:00Z');
16+
1317
// Type for raw portal JSON data - using `any` is acceptable here since we're dealing with
1418
// dynamic external API responses that we don't control
1519
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -254,13 +258,23 @@ async function processCaseDataRecord(
254258
receiptHandle: string
255259
): Promise<FetchStatus> {
256260
try {
257-
// Check for existing data and skip if already complete
261+
// Check for existing data and skip if already complete with current schema version.
258262
const zipCase = await StorageClient.getCase(caseNumber);
259263
if (zipCase && zipCase.fetchStatus.status === 'complete') {
260-
// Always use the cached data for complete cases
261-
await QueueClient.deleteMessage(receiptHandle, 'data');
262-
console.log(`Case ${caseNumber} already complete; using cached data and deleted queue item`);
263-
return zipCase.fetchStatus;
264+
const lastUpdated = zipCase.lastUpdated ? new Date(zipCase.lastUpdated) : new Date(0);
265+
266+
if (lastUpdated.getTime() >= CASE_SUMMARY_VERSION_DATE.getTime()) {
267+
// Cached summary is new enough for current version - use it
268+
await QueueClient.deleteMessage(receiptHandle, 'data');
269+
console.log(
270+
`Case ${caseNumber} already complete and up-to-date (lastUpdated=${zipCase.lastUpdated}); using cached data`
271+
);
272+
return zipCase.fetchStatus;
273+
}
274+
275+
console.log(
276+
`Case ${caseNumber} lastUpdated (${zipCase.lastUpdated}) is older than version date ${CASE_SUMMARY_VERSION_DATE.toISOString()}; re-fetching case summary`
277+
);
264278
}
265279

266280
// Fetch case summary

serverless/lib/CaseSearchProcessor.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import axios from 'axios';
99
import { wrapper } from 'axios-cookiejar-support';
1010
import * as cheerio from 'cheerio';
1111
import UserAgentClient from './UserAgentClient';
12+
import { CASE_SUMMARY_VERSION_DATE } from './CaseProcessor';
1213

1314
// Process API case search requests
1415
export async function processCaseSearchRequest(req: CaseSearchRequest): Promise<CaseSearchResponse> {
@@ -54,27 +55,30 @@ export async function processCaseSearchRequest(req: CaseSearchRequest): Promise<
5455

5556
switch (status) {
5657
case 'complete':
57-
if (caseSummary) {
58-
// Truly complete - has both ID and summary
59-
console.log(`Case ${caseNumber} is complete with summary, preserving`);
58+
const lastUpdated = results[caseNumber].zipCase.lastUpdated;
59+
if (caseSummary && lastUpdated && new Date(lastUpdated) >= CASE_SUMMARY_VERSION_DATE) {
60+
// Truly complete - has both ID and an up-to-date summary
61+
console.log(`Case ${caseNumber} is complete with up-to-date summary schema, preserving`);
6062
continue;
6163
} else if (caseId) {
62-
// Has ID but missing summary - treat as 'found' and queue for data retrieval
64+
// Has ID but missing summary or summary schema is outdated - treat as 'found' and queue for data retrieval
6365
console.log(
64-
`Case ${caseNumber} has 'complete' status but missing summary, treating as 'found' and queueing for data retrieval`
66+
`Case ${caseNumber} has 'complete' status but ${caseSummary ? 'summary is outdated' : 'missing summary'}; treating as 'found' and queueing for data retrieval`
6567
);
6668

67-
// Update status to 'found' since we need to rebuild the summary
69+
const nowString = new Date().toISOString();
70+
71+
// Update status to 'found', since we need to rebuild the summary
6872
await StorageClient.saveCase({
6973
caseNumber,
7074
caseId,
7175
fetchStatus: { status: 'found' },
72-
lastUpdated: new Date().toISOString(),
76+
lastUpdated: nowString,
7377
});
7478

7579
// Also update the results object that will be returned to frontend
7680
results[caseNumber].zipCase.fetchStatus = { status: 'found' };
77-
results[caseNumber].zipCase.lastUpdated = new Date().toISOString();
81+
results[caseNumber].zipCase.lastUpdated = nowString;
7882

7983
try {
8084
await QueueClient.queueCaseForDataRetrieval(caseNumber, caseId, req.userId);

0 commit comments

Comments
 (0)