mailru: skip extra http request if data fits in hash
This commit is contained in:
parent
8fb44a822d
commit
8fe87c8157
1 changed files with 19 additions and 14 deletions
|
@ -1584,21 +1584,26 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||||
fileBuf []byte
|
fileBuf []byte
|
||||||
fileHash []byte
|
fileHash []byte
|
||||||
newHash []byte
|
newHash []byte
|
||||||
|
trySpeedup bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// Request hash from source
|
// Don't disturb the source if file fits in hash.
|
||||||
|
// Skip an extra speedup request if file fits in hash.
|
||||||
|
if size > mrhash.Size {
|
||||||
|
// Request hash from source.
|
||||||
if srcHash, err := src.Hash(ctx, hash.Mailru); err == nil && srcHash != "" {
|
if srcHash, err := src.Hash(ctx, hash.Mailru); err == nil && srcHash != "" {
|
||||||
fileHash, _ = mrhash.DecodeString(srcHash)
|
fileHash, _ = mrhash.DecodeString(srcHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try speedup method if it's globally enabled and source hash is available
|
// Try speedup if it's globally enabled and source hash is available.
|
||||||
trySpeedup := o.fs.opt.SpeedupEnable
|
trySpeedup = o.fs.opt.SpeedupEnable
|
||||||
if trySpeedup && fileHash != nil {
|
if trySpeedup && fileHash != nil {
|
||||||
if o.putByHash(ctx, fileHash, src, "source") {
|
if o.putByHash(ctx, fileHash, src, "source") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
trySpeedup = false // speedup failed, force upload
|
trySpeedup = false // speedup failed, force upload
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Need to calculate hash, check whether file is still eligible for speedup
|
// Need to calculate hash, check whether file is still eligible for speedup
|
||||||
if trySpeedup {
|
if trySpeedup {
|
||||||
|
|
Loading…
Reference in a new issue