File tree Expand file tree Collapse file tree 2 files changed +26
-14
lines changed Expand file tree Collapse file tree 2 files changed +26
-14
lines changed Original file line number Diff line number Diff line change @@ -64,9 +64,9 @@ const GodModePublishingPage: NextPageWithLayout = () => {
64
64
65
65
const { mutate : publishAllSite , isLoading : isPublishingAllSite } =
66
66
trpc . site . publishAll . useMutation ( {
67
- onSuccess : ( ) => {
67
+ onSuccess : ( { siteCount } ) => {
68
68
toast ( {
69
- title : "All sites published successfully" ,
69
+ title : `Starting to publish ${ siteCount } sites in the background...` ,
70
70
status : "success" ,
71
71
...BRIEF_TOAST_SETTINGS ,
72
72
} )
Original file line number Diff line number Diff line change @@ -406,19 +406,31 @@ export const siteRouter = router({
406
406
. where ( "codeBuildId" , "is not" , null )
407
407
. execute ( )
408
408
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" ,
417
427
siteId : site . id ,
428
+ error,
418
429
} )
419
- await publishSite ( ctx . logger , site . id )
420
- } ) ,
421
- ) ,
422
- )
430
+ }
431
+ }
432
+ } ) ( )
433
+
434
+ return { siteCount : sites . length }
423
435
} ) ,
424
436
} )
You can’t perform that action at this time.
0 commit comments