From cbdd116cea26cd648d90ecabec7082fe08cfae30 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Sat, 20 Apr 2024 12:49:28 +0530 Subject: [PATCH] [server] Copy thumb and file in parallel --- server/pkg/controller/file_copy/file_copy.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/server/pkg/controller/file_copy/file_copy.go b/server/pkg/controller/file_copy/file_copy.go index 1d8b888ac..7c50e1c3a 100644 --- a/server/pkg/controller/file_copy/file_copy.go +++ b/server/pkg/controller/file_copy/file_copy.go @@ -12,6 +12,7 @@ import ( "github.com/gin-contrib/requestid" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "golang.org/x/sync/errgroup" "sync" "time" ) @@ -166,12 +167,14 @@ func (fc *FileCopyController) createCopy(c *gin.Context, fcInternal fileCopyInte // using HotS3Client copy the File and Thumbnail s3Client := fc.S3Config.GetHotS3Client() hotBucket := fc.S3Config.GetHotBucket() - err := copyS3Object(s3Client, hotBucket, fcInternal.FileCopyReq) - if err != nil { - return nil, err - } - err = copyS3Object(s3Client, hotBucket, fcInternal.ThumbCopyReq) - if err != nil { + g := new(errgroup.Group) + g.Go(func() error { + return copyS3Object(s3Client, hotBucket, fcInternal.FileCopyReq) + }) + g.Go(func() error { + return copyS3Object(s3Client, hotBucket, fcInternal.ThumbCopyReq) + }) + if err := g.Wait(); err != nil { return nil, err } file := fcInternal.newFile(userID)