Skip to content

Commit f440743

Browse files
committed
perf(medusa): O(n) translations batch matching via Set lookups
The translations batch endpoint matched fetched rows against the workflow result with translations.filter(t => result.created.some(r => r.id === t.id)), once per row — O(n²) over the batch size, which is user-controlled. Build Sets of created/updated ids once and test membership in O(1). Mirrors the existing Set-based id dedup a few lines above. Behaviour is identical.
1 parent e5fb75c commit f440743

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/medusa": patch
3+
---
4+
5+
perf(medusa): avoid O(n²) matching in the translations batch endpoint by using Sets for created/updated id lookups

packages/medusa/src/api/admin/translations/batch/route.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ export const POST = async (
4747
},
4848
})
4949

50-
const created = translations.filter((t) =>
51-
result.created.some((r) => r.id === t.id)
52-
)
53-
const updated = translations.filter((t) =>
54-
result.updated.some((r) => r.id === t.id)
55-
)
50+
const createdIds = new Set(result.created.map((r) => r.id))
51+
const updatedIds = new Set(result.updated.map((r) => r.id))
52+
53+
const created = translations.filter((t) => createdIds.has(t.id))
54+
const updated = translations.filter((t) => updatedIds.has(t.id))
5655

5756
return res.status(200).json({
5857
created,

0 commit comments

Comments
 (0)