mirror of
https://github.com/alist-org/gofakes3.git
synced 2025-12-24 12:58:04 +08:00
Move PutObject body read outside lock
This commit is contained in:
@@ -216,6 +216,14 @@ func (db *Backend) GetObject(bucketName, objectName string, rangeRequest *gofake
|
||||
}
|
||||
|
||||
func (db *Backend) PutObject(bucketName, objectName string, meta map[string]string, input io.Reader, size int64) (result gofakes3.PutObjectResult, err error) {
|
||||
// No need to lock the backend while we read the data into memory; it holds
|
||||
// the write lock open unnecessarily, and could be blocked for an unreasonably
|
||||
// long time by a connection timing out:
|
||||
bts, err := gofakes3.ReadAll(input, size)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
db.lock.Lock()
|
||||
defer db.lock.Unlock()
|
||||
|
||||
@@ -224,11 +232,6 @@ func (db *Backend) PutObject(bucketName, objectName string, meta map[string]stri
|
||||
return result, gofakes3.BucketNotFound(bucketName)
|
||||
}
|
||||
|
||||
bts, err := gofakes3.ReadAll(input, size)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
hash := md5.Sum(bts)
|
||||
|
||||
item := &bucketData{
|
||||
|
||||
Reference in New Issue
Block a user