Skip to content

Commit a160c8e

Browse files
committed
simplify namespace filtering logic
1 parent 03bb2d2 commit a160c8e

File tree

5 files changed

+10360
-37
lines changed

5 files changed

+10360
-37
lines changed

apps/sim/lib/core/idempotency/service.ts

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { randomUUID } from 'crypto'
22
import { db } from '@sim/db'
33
import { idempotencyKey } from '@sim/db/schema'
44
import { createLogger } from '@sim/logger'
5-
import { and, eq } from 'drizzle-orm'
5+
import { eq } from 'drizzle-orm'
66
import { getRedisClient } from '@/lib/core/config/redis'
77
import { getStorageMethod, type StorageMethod } from '@/lib/core/storage'
88
import { extractProviderIdentifierFromBody } from '@/lib/webhooks/provider-utils'
@@ -124,12 +124,7 @@ export class IdempotencyService {
124124
const existing = await db
125125
.select({ result: idempotencyKey.result, createdAt: idempotencyKey.createdAt })
126126
.from(idempotencyKey)
127-
.where(
128-
and(
129-
eq(idempotencyKey.key, normalizedKey),
130-
eq(idempotencyKey.namespace, this.config.namespace)
131-
)
132-
)
127+
.where(eq(idempotencyKey.key, normalizedKey))
133128
.limit(1)
134129

135130
if (existing.length > 0) {
@@ -148,12 +143,7 @@ export class IdempotencyService {
148143

149144
await db
150145
.delete(idempotencyKey)
151-
.where(
152-
and(
153-
eq(idempotencyKey.key, normalizedKey),
154-
eq(idempotencyKey.namespace, this.config.namespace)
155-
)
156-
)
146+
.where(eq(idempotencyKey.key, normalizedKey))
157147
.catch((err) => logger.warn(`Failed to clean up expired key ${normalizedKey}:`, err))
158148
}
159149

@@ -229,12 +219,11 @@ export class IdempotencyService {
229219
.insert(idempotencyKey)
230220
.values({
231221
key: normalizedKey,
232-
namespace: this.config.namespace,
233222
result: inProgressResult,
234223
createdAt: new Date(),
235224
})
236225
.onConflictDoNothing({
237-
target: [idempotencyKey.key, idempotencyKey.namespace],
226+
target: idempotencyKey.key,
238227
})
239228
.returning({ key: idempotencyKey.key })
240229

@@ -250,12 +239,7 @@ export class IdempotencyService {
250239
const existing = await db
251240
.select({ result: idempotencyKey.result })
252241
.from(idempotencyKey)
253-
.where(
254-
and(
255-
eq(idempotencyKey.key, normalizedKey),
256-
eq(idempotencyKey.namespace, this.config.namespace)
257-
)
258-
)
242+
.where(eq(idempotencyKey.key, normalizedKey))
259243
.limit(1)
260244

261245
const existingResult =
@@ -287,12 +271,7 @@ export class IdempotencyService {
287271
const existing = await db
288272
.select({ result: idempotencyKey.result })
289273
.from(idempotencyKey)
290-
.where(
291-
and(
292-
eq(idempotencyKey.key, normalizedKey),
293-
eq(idempotencyKey.namespace, this.config.namespace)
294-
)
295-
)
274+
.where(eq(idempotencyKey.key, normalizedKey))
296275
.limit(1)
297276
currentResult = existing.length > 0 ? (existing[0].result as ProcessingResult) : null
298277
}
@@ -346,12 +325,11 @@ export class IdempotencyService {
346325
.insert(idempotencyKey)
347326
.values({
348327
key: normalizedKey,
349-
namespace: this.config.namespace,
350328
result: result,
351329
createdAt: new Date(),
352330
})
353331
.onConflictDoUpdate({
354-
target: [idempotencyKey.key, idempotencyKey.namespace],
332+
target: idempotencyKey.key,
355333
set: {
356334
result: result,
357335
createdAt: new Date(),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DROP INDEX "idempotency_key_namespace_unique";--> statement-breakpoint
2+
DROP INDEX "idempotency_key_namespace_idx";--> statement-breakpoint
3+
ALTER TABLE "idempotency_key" ADD PRIMARY KEY ("key");--> statement-breakpoint
4+
ALTER TABLE "idempotency_key" DROP COLUMN "namespace";

0 commit comments

Comments
 (0)