[server] Copy thumb and file in parallel

This commit is contained in:
Neeraj Gupta
2024-04-20 12:49:28 +05:30
parent 91620965b0
commit cbdd116cea

View File

@@ -12,6 +12,7 @@ import (
"github.com/gin-contrib/requestid" "github.com/gin-contrib/requestid"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
"sync" "sync"
"time" "time"
) )
@@ -166,12 +167,14 @@ func (fc *FileCopyController) createCopy(c *gin.Context, fcInternal fileCopyInte
// using HotS3Client copy the File and Thumbnail // using HotS3Client copy the File and Thumbnail
s3Client := fc.S3Config.GetHotS3Client() s3Client := fc.S3Config.GetHotS3Client()
hotBucket := fc.S3Config.GetHotBucket() hotBucket := fc.S3Config.GetHotBucket()
err := copyS3Object(s3Client, hotBucket, fcInternal.FileCopyReq) g := new(errgroup.Group)
if err != nil { g.Go(func() error {
return nil, err return copyS3Object(s3Client, hotBucket, fcInternal.FileCopyReq)
} })
err = copyS3Object(s3Client, hotBucket, fcInternal.ThumbCopyReq) g.Go(func() error {
if err != nil { return copyS3Object(s3Client, hotBucket, fcInternal.ThumbCopyReq)
})
if err := g.Wait(); err != nil {
return nil, err return nil, err
} }
file := fcInternal.newFile(userID) file := fcInternal.newFile(userID)