From: Colin Marc Date: Mon, 13 Feb 2023 03:26:03 +0000 (+0100) Subject: Remove unecessary completion "set" (#812) X-Git-Tag: v1.49.0~13 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=60fd7581e774c14a4d370b90672012b58a2739f4;p=btrtrc.git Remove unecessary completion "set" (#812) If the file has never been downloaded, complete will naturally be false. It's not necessary to then set it false again unless it was actually claimed to be true in the first place. In my tests, using the boltdb completion thingy with fsync turned *on*, this reduced the cold start for big buck bunny from multiple seconds to just a few ms. --- diff --git a/storage/file-piece.go b/storage/file-piece.go index 23cf4eec..47772017 100644 --- a/storage/file-piece.go +++ b/storage/file-piece.go @@ -28,20 +28,25 @@ func (fs *filePieceImpl) Completion() Completion { c.Ok = false return c } + + verified := true if c.Complete { // If it's allegedly complete, check that its constituent files have the necessary length. for _, fi := range extentCompleteRequiredLengths(fs.p.Info, fs.p.Offset(), fs.p.Length()) { s, err := os.Stat(fs.files[fi.fileIndex].path) if err != nil || s.Size() < fi.length { - c.Complete = false + verified = false break } } } - if !c.Complete { + + if !verified { // The completion was wrong, fix it. + c.Complete = false fs.completion.Set(fs.pieceKey(), false) } + return c }