Skip to content

Commit a83357d

Browse files
authored
Fix godmode publishall (#1364)
* refactor(site.router): implement background processing for site publishing * fix(publishing): update success toast message to reflect site count during background publishing
1 parent fddb20f commit a83357d

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

apps/studio/src/pages/godmode/publishing.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ const GodModePublishingPage: NextPageWithLayout = () => {
6464

6565
const { mutate: publishAllSite, isLoading: isPublishingAllSite } =
6666
trpc.site.publishAll.useMutation({
67-
onSuccess: () => {
67+
onSuccess: ({ siteCount }) => {
6868
toast({
69-
title: "All sites published successfully",
69+
title: `Starting to publish ${siteCount} sites in the background...`,
7070
status: "success",
7171
...BRIEF_TOAST_SETTINGS,
7272
})

apps/studio/src/server/modules/site/site.router.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -406,19 +406,31 @@ export const siteRouter = router({
406406
.where("codeBuildId", "is not", null)
407407
.execute()
408408

409-
await Promise.all(
410-
sites.map((site) =>
411-
db.transaction().execute(async (tx) => {
412-
await logPublishEvent(tx, {
413-
by: byUser,
414-
eventType: AuditLogEvent.Publish,
415-
delta: { before: null, after: null },
416-
metadata: {},
409+
// Start background processing to not block the main thread and avoid timeouts
410+
void (async () => {
411+
// Looping intsead of Promise.all to avoid maxing out Prisma's connection pool
412+
for (const site of sites) {
413+
try {
414+
await db.transaction().execute(async (tx) => {
415+
await logPublishEvent(tx, {
416+
by: byUser,
417+
eventType: AuditLogEvent.Publish,
418+
delta: { before: null, after: null },
419+
metadata: {},
420+
siteId: site.id,
421+
})
422+
await publishSite(ctx.logger, site.id)
423+
})
424+
} catch (error) {
425+
ctx.logger.error({
426+
msg: "Failed to publish site",
417427
siteId: site.id,
428+
error,
418429
})
419-
await publishSite(ctx.logger, site.id)
420-
}),
421-
),
422-
)
430+
}
431+
}
432+
})()
433+
434+
return { siteCount: sites.length }
423435
}),
424436
})

0 commit comments

Comments
 (0)