Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[server] Copy files in parallel

Neeraj Gupta5a5e3d28cbe5
diff --git a/server/pkg/controller/file_copy/file_copy.go b/server/pkg/controller/file_copy/file_copy.go
index 5016a65367..9923e4b678 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"
+ "sync"
"time"
)
@@ -133,12 +134,29 @@ func (fc *FileCopyController) CopyFiles(c *gin.Context, req ente.CopyFileSyncReq
fileCopyList = append(fileCopyList, fileCopy)
}
oldToNewFileIDMap := make(map[int64]int64)
+ var wg sync.WaitGroup
+ errChan := make(chan error, len(fileCopyList))
+
for _, fileCopy := range fileCopyList {
- newFile, err := fc.createCopy(c, fileCopy, userID, app)
- if err != nil {
- return nil, err
- }
- oldToNewFileIDMap[fileCopy.SourceFile.ID] = newFile.ID
+ wg.Add(1)
+ go func(fileCopy fileCopyInternal) {
+ defer wg.Done()
+ newFile, err := fc.createCopy(c, fileCopy, userID, app)
+ if err != nil {
+ errChan <- err
+ return
+ }
+ oldToNewFileIDMap[fileCopy.SourceFile.ID] = newFile.ID
+ }(fileCopy)
+ }
+
+ // Wait for all goroutines to finish
+ wg.Wait()
+
+ // Close the error channel and check if there were any errors
+ close(errChan)
+ if err, ok := <-errChan; ok {
+ return nil, err
}
return &ente.CopyResponse{OldToNewFileIDMap: oldToNewFileIDMap}, nil
}