Skip to content

Commit a2761da

Browse files
committed
fix: concurrent upload to strapi based on content type
1 parent 0c99f7d commit a2761da

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

cms/scripts/sync-mdx/syncCoordinator.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,24 +140,26 @@ export async function syncAll(
140140
errors: 0
141141
}
142142

143-
for (const contentType of Object.keys(ctx.contentTypes) as Array<
144-
keyof ContentTypes
145-
>) {
146-
try {
147-
const results = await syncContentType(contentType, ctx, dryRun)
148-
allResults.created += results.created
149-
allResults.updated += results.updated
150-
allResults.deleted += results.deleted
151-
allResults.errors += results.errors
152-
} catch (error) {
153-
// syncContentType doesn't return Error directly (it accumulates errors
154-
// into the per-content-type SyncResults), but we keep this guard for
155-
// truly unexpected exceptions (programmer bugs, OOM, etc).
156-
console.error(
157-
`\n❌ Error syncing ${contentType}: ${(error as Error).message}`
158-
)
159-
allResults.errors++
160-
}
143+
const perTypeResults = await Promise.all(
144+
(Object.keys(ctx.contentTypes) as Array<keyof ContentTypes>).map(
145+
(contentType) =>
146+
syncContentType(contentType, ctx, dryRun).catch((error) => {
147+
// syncContentType doesn't return Error directly (it accumulates errors
148+
// into the per-content-type SyncResults), but we keep this guard for
149+
// truly unexpected exceptions (programmer bugs, OOM, etc).
150+
console.error(
151+
`\n❌ Error syncing ${contentType}: ${(error as Error).message}`
152+
)
153+
return { created: 0, updated: 0, deleted: 0, errors: 1 }
154+
})
155+
)
156+
)
157+
158+
for (const results of perTypeResults) {
159+
allResults.created += results.created
160+
allResults.updated += results.updated
161+
allResults.deleted += results.deleted
162+
allResults.errors += results.errors
161163
}
162164

163165
return allResults

0 commit comments

Comments
 (0)