Skip to content

Commit 748adce

Browse files
committed
Fix cache wipe issue demontrated in previous commit integration test
1 parent 5d80fb0 commit 748adce

File tree

6 files changed

+8
-92
lines changed

6 files changed

+8
-92
lines changed

src/read-models/shared-state/async-apply-external-event-sources.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as E from 'fp-ts/Either';
33
import * as O from 'fp-ts/Option';
44
import {DomainEvent} from '../../types';
55
import {BetterSQLite3Database} from 'drizzle-orm/better-sqlite3';
6-
import {EpochTimestampMilliseconds} from './return-types';
76

87
import {constructEvent, EventOfType} from '../../types/domain-event';
98
import {GoogleHelpers} from '../../init-dependencies/google/pull_sheet_data';
@@ -22,7 +21,6 @@ import {
2221
} from '../../training-sheets/google';
2322
import {getChunkIndexes} from '../../util';
2423
import {UUID} from 'io-ts-types';
25-
import {expandLastQuizResult} from './equipment/expand';
2624

2725
const ROW_BATCH_SIZE = 200;
2826

@@ -31,7 +29,6 @@ const pullNewEquipmentQuizResultsForSheet = async (
3129
googleHelpers: GoogleHelpers,
3230
equipmentId: UUID,
3331
trainingSheetId: string,
34-
eventsFromExclusive: O.Option<EpochTimestampMilliseconds>,
3532
sheet: GoogleSheetMetadata,
3633
timezone: string,
3734
updateState: (event: EventOfType<'EquipmentTrainingQuizResult'>) => void
@@ -71,8 +68,7 @@ const pullNewEquipmentQuizResultsForSheet = async (
7168
trainingSheetId,
7269
equipmentId,
7370
sheet,
74-
timezone,
75-
eventsFromExclusive
71+
timezone
7672
)(data.right);
7773
logger.info(
7874
'Google sheet data extracted, updating data with the extracted data...'
@@ -89,7 +85,6 @@ export const pullNewEquipmentQuizResults = async (
8985
googleHelpers: GoogleHelpers,
9086
equipmentId: UUID,
9187
trainingSheetId: string,
92-
eventsSinceExclusive: O.Option<EpochTimestampMilliseconds>,
9388
updateState: (
9489
event:
9590
| EventOfType<'EquipmentTrainingQuizSync'>
@@ -155,7 +150,6 @@ export const pullNewEquipmentQuizResults = async (
155150
googleHelpers,
156151
equipmentId,
157152
trainingSheetId,
158-
eventsSinceExclusive,
159153
sheet,
160154
initialMeta.right.properties.timeZone,
161155
updateState
@@ -220,7 +214,6 @@ export const asyncApplyExternalEventSources = (
220214
googleHelpers.value,
221215
equipment.id,
222216
equipment.trainingSheetId.value,
223-
expandLastQuizResult(currentState)(equipment).lastQuizResult,
224217
collectEvents
225218
);
226219
equipmentLogger.info(

src/read-models/shared-state/equipment/expand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ const expandOrphanedTrainingQuizes =
228228
),
229229
});
230230

231-
export const expandLastQuizResult =
231+
const expandLastQuizResult =
232232
(db: BetterSQLite3Database) =>
233233
<T extends MinimalEquipment>(
234234
equipment: T

src/training-sheets/google.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,7 @@ export const extractGoogleSheetData =
262262
trainingSheetId: string,
263263
equipmentId: UUID,
264264
metadata: GoogleSheetMetadata,
265-
timezone: string,
266-
// Note we filter events on timestamp rather than last row currently to handle
267-
// blank rows but potentially we could switch if we added detection for blank rows.
268-
eventsFromExclusive: O.Option<EpochTimestampMilliseconds>
265+
timezone: string
269266
) =>
270267
(
271268
spreadsheet: GoogleSpreadsheetDataForSheet
@@ -287,12 +284,7 @@ export const extractGoogleSheetData =
287284
timezone
288285
)
289286
),
290-
RA.filterMap(e => e),
291-
RA.filter(
292-
e =>
293-
O.isNone(eventsFromExclusive) ||
294-
e.timestampEpochMS > eventsFromExclusive.value
295-
)
287+
RA.filterMap(e => e)
296288
)
297289
)
298290
)

tests/training-sheets/extract-google-sheet-data.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ describe('extractGoogleSheetData', () => {
2121
memberNumber: O.some(2),
2222
},
2323
},
24-
'Europe/London',
25-
O.none
24+
'Europe/London'
2625
)({
2726
sheets: [
2827
{

tests/training-sheets/integration.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
} from '../../src/init-dependencies/google/pull_sheet_data';
1313
import {GoogleAuth} from 'google-auth-library/build/src/auth/googleauth';
1414
import {UUID} from 'io-ts-types';
15-
import * as O from 'fp-ts/Option';
1615
import * as RA from 'fp-ts/ReadonlyArray';
1716
import * as N from 'fp-ts/number';
1817
import {DomainEvent} from '../../src/types';
@@ -44,7 +43,6 @@ const getEvents = async (trainingSheetId: string) => {
4443
},
4544
TEST_EQUIPMENT_ID,
4645
trainingSheetId,
47-
O.none,
4846
event => events.push(event)
4947
);
5048
return events;

tests/training-sheets/process-events.test.ts

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import {
77
import pino from 'pino';
88
import * as RA from 'fp-ts/lib/ReadonlyArray';
99
import * as N from 'fp-ts/number';
10-
import * as O from 'fp-ts/Option';
1110
import * as gsheetData from '../data/google_sheet_data';
1211
import {pullNewEquipmentQuizResults} from '../../src/read-models/shared-state/async-apply-external-event-sources';
13-
import {EpochTimestampMilliseconds} from '../../src/read-models/shared-state/return-types';
1412
import {localGoogleHelpers} from '../init-dependencies/pull-local-google';
1513

1614
const sortQuizResults = RA.sort({
@@ -28,8 +26,7 @@ const sortQuizResults = RA.sort({
2826

2927
const pullNewEquipmentQuizResultsLocal = async (
3028
equipmentId: UUID,
31-
trainingSheetId: string,
32-
eventsSinceExclusive: O.Option<EpochTimestampMilliseconds>
29+
trainingSheetId: string
3330
) => {
3431
const newEvents: DomainEvent[] = [];
3532
await pullNewEquipmentQuizResults(
@@ -40,7 +37,6 @@ const pullNewEquipmentQuizResultsLocal = async (
4037
localGoogleHelpers,
4138
equipmentId,
4239
trainingSheetId,
43-
eventsSinceExclusive,
4440
newEvent => {
4541
newEvents.push(newEvent);
4642
}
@@ -57,14 +53,12 @@ type EquipmentQuizResultEvents = {
5753
endTime: Date;
5854
};
5955
const pullEquipmentQuizResultsWrapper = async (
60-
spreadsheetId: string,
61-
lastQuizResult: O.Option<EpochTimestampMilliseconds> = O.none
56+
spreadsheetId: string
6257
): Promise<EquipmentQuizResultEvents> => {
6358
const startTime = new Date();
6459
const events = await pullNewEquipmentQuizResultsLocal(
6560
TEST_EQUIPMENT_ID,
66-
spreadsheetId,
67-
lastQuizResult
61+
spreadsheetId
6862
);
6963
const endTime = new Date();
7064
const result = {
@@ -175,66 +169,6 @@ describe('Training sheets worker', () => {
175169
>(expectedEvent);
176170
}
177171
});
178-
it('Only take new rows, date in future', async () => {
179-
const results = await pullEquipmentQuizResultsWrapper(
180-
gsheetData.BAMBU.apiResp.spreadsheetId!,
181-
O.some(Date.now() as EpochTimestampMilliseconds)
182-
);
183-
checkQuizSync(results);
184-
expect(results.quizResults).toHaveLength(0);
185-
});
186-
it('Only take new rows, date in far past', async () => {
187-
const results = await pullEquipmentQuizResultsWrapper(
188-
gsheetData.BAMBU.apiResp.spreadsheetId!,
189-
O.some(0 as EpochTimestampMilliseconds)
190-
);
191-
checkQuizSync(results);
192-
expect(results.quizResults).toHaveLength(
193-
gsheetData.BAMBU.entries.length
194-
);
195-
});
196-
197-
// The quiz results have dates:
198-
// 1700768963 Thursday, November 23, 2023 7:49:23 PM
199-
// 1700769348 Thursday, November 23, 2023 7:55:48 PM
200-
// 1710249052 Tuesday, March 12, 2024 1:10:52 PM
201-
// 1710249842 Tuesday, March 12, 2024 1:24:02 PM
202-
203-
it('Only take new rows, exclude 1', async () => {
204-
const results = await pullEquipmentQuizResultsWrapper(
205-
gsheetData.BAMBU.apiResp.spreadsheetId!,
206-
O.some(1700768963_000 as EpochTimestampMilliseconds)
207-
);
208-
checkQuizSync(results);
209-
expect(results.quizResults).toHaveLength(3);
210-
});
211-
212-
it('Only take new rows, exclude 2', async () => {
213-
const results = await pullEquipmentQuizResultsWrapper(
214-
gsheetData.BAMBU.apiResp.spreadsheetId!,
215-
O.some(1700769348_000 as EpochTimestampMilliseconds)
216-
);
217-
checkQuizSync(results);
218-
expect(results.quizResults).toHaveLength(2);
219-
});
220-
221-
it('Only take new rows, exclude 3', async () => {
222-
const results = await pullEquipmentQuizResultsWrapper(
223-
gsheetData.BAMBU.apiResp.spreadsheetId!,
224-
O.some(1710249052_000 as EpochTimestampMilliseconds)
225-
);
226-
checkQuizSync(results);
227-
expect(results.quizResults).toHaveLength(1);
228-
});
229-
230-
it('Only take new rows, exclude all (already have latest)', async () => {
231-
const results = await pullEquipmentQuizResultsWrapper(
232-
gsheetData.BAMBU.apiResp.spreadsheetId!,
233-
O.some(1710249842_000 as EpochTimestampMilliseconds)
234-
);
235-
checkQuizSync(results);
236-
expect(results.quizResults).toHaveLength(0);
237-
});
238172
});
239173
});
240174
});

0 commit comments

Comments
 (0)