|
1 | 1 | import { |
2 | | - DistributedTransaction, |
3 | 2 | DistributedTransactionType, |
4 | 3 | IDistributedSchedulerStorage, |
5 | 4 | IDistributedTransactionStorage, |
@@ -274,14 +273,6 @@ export class RedisDistributedTransactionStorage |
274 | 273 | key: string, |
275 | 274 | options?: TransactionOptions & { isCancelling?: boolean } |
276 | 275 | ): Promise<TransactionCheckpoint | undefined> { |
277 | | - const data = await this.redisClient.get(key) |
278 | | - |
279 | | - if (data) { |
280 | | - const parsedData = JSON.parse(data) as TransactionCheckpoint |
281 | | - return parsedData |
282 | | - } |
283 | | - |
284 | | - // Not in Redis either - check database if needed |
285 | 276 | const { idempotent, store, retentionTime } = options ?? {} |
286 | 277 | if (!idempotent && !(store && isDefined(retentionTime))) { |
287 | 278 | return |
@@ -340,38 +331,6 @@ export class RedisDistributedTransactionStorage |
340 | 331 | return |
341 | 332 | } |
342 | 333 |
|
343 | | - async list(): Promise<TransactionCheckpoint[]> { |
344 | | - // Replace Redis KEYS with SCAN to avoid blocking the server |
345 | | - const transactions: TransactionCheckpoint[] = [] |
346 | | - let cursor = "0" |
347 | | - |
348 | | - do { |
349 | | - // Use SCAN instead of KEYS to avoid blocking Redis |
350 | | - const [nextCursor, keys] = await this.redisClient.scan( |
351 | | - cursor, |
352 | | - "MATCH", |
353 | | - DistributedTransaction.keyPrefix + ":*", |
354 | | - "COUNT", |
355 | | - 100 // Fetch in reasonable batches |
356 | | - ) |
357 | | - |
358 | | - cursor = nextCursor |
359 | | - |
360 | | - if (keys.length) { |
361 | | - // Use mget to batch retrieve multiple keys at once |
362 | | - const values = await this.redisClient.mget(keys) |
363 | | - |
364 | | - for (const value of values) { |
365 | | - if (value) { |
366 | | - transactions.push(JSON.parse(value)) |
367 | | - } |
368 | | - } |
369 | | - } |
370 | | - } while (cursor !== "0") |
371 | | - |
372 | | - return transactions |
373 | | - } |
374 | | - |
375 | 334 | async save( |
376 | 335 | key: string, |
377 | 336 | data: TransactionCheckpoint, |
@@ -408,7 +367,11 @@ export class RedisDistributedTransactionStorage |
408 | 367 | const shouldSetNX = isNotStarted && isManualTransactionId |
409 | 368 |
|
410 | 369 | // Prepare operations to be executed in batch or pipeline |
411 | | - const stringifiedData = JSON.stringify(data) |
| 370 | + const data_ = { |
| 371 | + errors: data.errors, |
| 372 | + flow: data.flow, |
| 373 | + } |
| 374 | + const stringifiedData = JSON.stringify(data_) |
412 | 375 | const pipeline = this.redisClient.pipeline() |
413 | 376 |
|
414 | 377 | // Execute Redis operations |
@@ -658,14 +621,20 @@ export class RedisDistributedTransactionStorage |
658 | 621 | */ |
659 | 622 | const currentFlow = data.flow |
660 | 623 |
|
661 | | - const getOptions = { |
662 | | - ...options, |
663 | | - isCancelling: !!data.flow.cancelledAt, |
664 | | - } as Parameters<typeof this.get>[1] |
| 624 | + // const getOptions = { |
| 625 | + // ...options, |
| 626 | + // isCancelling: !!data.flow.cancelledAt, |
| 627 | + // } as Parameters<typeof this.get>[1] |
| 628 | + |
| 629 | + const rawData = await this.redisClient.get(key) |
| 630 | + let data_ = {} as TransactionCheckpoint |
| 631 | + if (rawData) { |
| 632 | + data_ = JSON.parse(rawData) |
| 633 | + } else { |
| 634 | + data_ = { flow: {} } as TransactionCheckpoint |
| 635 | + } |
665 | 636 |
|
666 | | - const { flow: latestUpdatedFlow } = |
667 | | - (await this.get(key, getOptions)) ?? |
668 | | - ({ flow: {} } as { flow: TransactionFlow }) |
| 637 | + const { flow: latestUpdatedFlow } = data_ |
669 | 638 |
|
670 | 639 | if (!isInitialCheckpoint && !isPresent(latestUpdatedFlow)) { |
671 | 640 | /** |
|
0 commit comments