mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
feat: improve upload file parallel
相同的文件不会并行上传
This commit is contained in:
parent
f7b2235a99
commit
3f91730dc4
@ -8,6 +8,7 @@ import (
|
||||
"math/rand"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
@ -54,6 +55,8 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
var fileSingleFlight = sync.Map{}
|
||||
|
||||
func init() {
|
||||
decoders["OidbSvc.0x6d8_1"] = decodeOIDB6d81Response
|
||||
decoders["OidbSvc.0x6d6_0"] = decodeOIDB6d60Response
|
||||
@ -156,6 +159,17 @@ func (fs *GroupFileSystem) GetFilesByFolder(folderId string) ([]*GroupFile, []*G
|
||||
}
|
||||
|
||||
func (fs *GroupFileSystem) UploadFile(p, name, folderId string) error {
|
||||
// 同文件等待其他线程上传
|
||||
if wg, ok := fileSingleFlight.Load(p); ok {
|
||||
wg.(*sync.WaitGroup).Wait()
|
||||
} else {
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
fileSingleFlight.Store(p, wg)
|
||||
defer wg.Done()
|
||||
defer fileSingleFlight.Delete(p)
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(p, os.O_RDONLY, 0666)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "open file error")
|
||||
|
Loading…
x
Reference in New Issue
Block a user