Skip to content

Commit 1b05c31

Browse files
committed
chore: 优化分片上传
- 超时时间默认24小时 - 加速分片记录的删除
1 parent 3d232ce commit 1b05c31

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

cache/upload.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func FindMutUpload(fn func(key string, entity *MutUpload) bool) ([]*MutUpload, e
5353
}
5454

5555
// 删除过期的分片上传记录
56-
if time.Since(item.CreateAt).Hours() > 12 {
56+
if time.Since(item.CreateAt).Hours() > 24 {
5757
FindMutUploadPart(func(key string, part *MutUploadPart) bool {
5858
if part.UploadID == item.UploadID {
5959
db.Delete([]byte(key), nil)
@@ -93,7 +93,11 @@ type MutUploadPart struct {
9393
}
9494

9595
func (p *MutUploadPart) Key() string {
96-
return fmt.Sprintf("part-%s-%d", p.UploadID, p.PartId)
96+
return fmt.Sprintf(
97+
"part-%x-%d",
98+
md5.Sum([]byte(p.UploadID)),
99+
p.PartId,
100+
)
97101
}
98102

99103
// 获取已经上传的分片
@@ -135,11 +139,12 @@ func DeleteByUploadID(uploadID string) error {
135139
}
136140
return false
137141
})
138-
FindMutUploadPart(func(key string, entity *MutUploadPart) bool {
139-
if entity.UploadID == uploadID {
140-
Delete(key)
141-
}
142-
return false
142+
h := fmt.Sprintf(
143+
"%x",
144+
md5.Sum([]byte(uploadID)),
145+
)
146+
Range("part-"+h, func(key, data []byte) {
147+
Delete(string(key))
143148
})
144149
return nil
145150
}

session.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,6 @@ func (sess *Session) putFileWithProgress(localPath, upPath string, localInfo os.
571571
}
572572

573573
// 上传分片任务
574-
fmt.Println(skips)
575574
uploader := partial.NewMultiPartialUploader(
576575
DefaultBlockSize,
577576
fd,

0 commit comments

Comments
 (0)