mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
fix(idempotency): use compatible PostgreSQL JSON operations (#6510)
This commit is contained in:
@@ -154,6 +154,8 @@ describe('IdempotencyService in-progress deadlines', () => {
|
||||
|
||||
const conflictOptions = dbChainMockFns.onConflictDoUpdate.mock.calls[0]?.[0]
|
||||
const setWhere = JSON.stringify(conflictOptions?.setWhere)
|
||||
expect(setWhere).toContain('json_typeof')
|
||||
expect(setWhere).not.toContain('jsonb_typeof')
|
||||
expect(setWhere).toContain('IS DISTINCT FROM')
|
||||
expect(setWhere).toContain('in-progress')
|
||||
})
|
||||
@@ -229,7 +231,8 @@ describe('IdempotencyService in-progress deadlines', () => {
|
||||
service.executeWithIdempotency('provider', 'delivery-retry-db', vi.fn())
|
||||
).resolves.toBe('new-owner-result')
|
||||
|
||||
const condition = dbChainMockFns.where.mock.calls.at(-1)?.[0]
|
||||
expect(JSON.stringify(condition)).toContain('retry me')
|
||||
const condition = JSON.stringify(dbChainMockFns.where.mock.calls.at(-1)?.[0])
|
||||
expect(condition).toContain('retry me')
|
||||
expect(condition.match(/::jsonb/g)).toHaveLength(2)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -327,7 +327,7 @@ export class IdempotencyService {
|
||||
const expiredBefore = new Date(now.getTime() - this.config.ttlSeconds * 1000)
|
||||
const inProgressClaimExpired = sql`COALESCE(
|
||||
CASE
|
||||
WHEN jsonb_typeof(${idempotencyKey.result} -> 'inProgressExpiresAt') = 'number'
|
||||
WHEN json_typeof(${idempotencyKey.result} -> 'inProgressExpiresAt') = 'number'
|
||||
THEN (${idempotencyKey.result} ->> 'inProgressExpiresAt')::double precision
|
||||
END,
|
||||
EXTRACT(EPOCH FROM ${idempotencyKey.createdAt}) * 1000 + ${this.config.inProgressTtlSeconds * 1000}
|
||||
@@ -548,7 +548,7 @@ export class IdempotencyService {
|
||||
: fence?.observedResult
|
||||
? and(
|
||||
eq(idempotencyKey.key, normalizedKey),
|
||||
sql`${idempotencyKey.result} = ${JSON.stringify(fence.observedResult)}::jsonb`
|
||||
sql`${idempotencyKey.result}::jsonb = ${JSON.stringify(fence.observedResult)}::jsonb`
|
||||
)
|
||||
: eq(idempotencyKey.key, normalizedKey)
|
||||
const deleted = await db
|
||||
|
||||
Reference in New Issue
Block a user