mailru: skip extra http request if data fits in hash

This commit is contained in:
Ivan Andreev 2019-09-10 21:16:35 +03:00 committed by Nick Craig-Wood
parent 8fb44a822d
commit 8fe87c8157

View file

@ -1581,23 +1581,28 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
} }
var ( var (
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.
if srcHash, err := src.Hash(ctx, hash.Mailru); err == nil && srcHash != "" { // Skip an extra speedup request if file fits in hash.
fileHash, _ = mrhash.DecodeString(srcHash) if size > mrhash.Size {
} // Request hash from source.
if srcHash, err := src.Hash(ctx, hash.Mailru); err == nil && srcHash != "" {
// Try speedup method if it's globally enabled and source hash is available fileHash, _ = mrhash.DecodeString(srcHash)
trySpeedup := o.fs.opt.SpeedupEnable }
if trySpeedup && fileHash != nil {
if o.putByHash(ctx, fileHash, src, "source") { // Try speedup if it's globally enabled and source hash is available.
return nil trySpeedup = o.fs.opt.SpeedupEnable
if trySpeedup && fileHash != nil {
if o.putByHash(ctx, fileHash, src, "source") {
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