From fa7b81e1cf3a38350253b3583e3326fc25dc2c41 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Fri, 2 May 2025 13:15:26 +0200 Subject: [PATCH] fix(model): use same folder first in copier (#10093) Where `folderFilesystems` and `folders` is built, there's a comment spelling out the purpose: To have the same folder first, as that's the most likely to get hits. Plus a copy is possibly more efficient than from another folder, e.g. if that's on a different filesystem. We lost that behaviour during some unrelated change. (Also sneaking in a comment fix on yesterdays change.) --- lib/model/folder_sendrecv.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/model/folder_sendrecv.go b/lib/model/folder_sendrecv.go index bff10380a..101324b9e 100644 --- a/lib/model/folder_sendrecv.go +++ b/lib/model/folder_sendrecv.go @@ -1346,7 +1346,10 @@ func (f *sendReceiveFolder) copierRoutine(in <-chan copyBlocksState, pullChan ch copied := false folders: - for folderID, ffs := range folderFilesystems { + // Intentionally not iterating over `folderFilesystems` directly, + // to preserve order (same folder first). + for _, folderID := range folders { + ffs := folderFilesystems[folderID] for e, err := range itererr.Zip(f.model.sdb.AllLocalBlocksWithHash(folderID, block.Hash)) { if err != nil { // We just ignore this and continue pulling instead (though @@ -1393,7 +1396,7 @@ func (f *sendReceiveFolder) copierRoutine(in <-chan copyBlocksState, pullChan ch } } -// Returns true, if the block was successfully copied to buf. The returned +// Returns true, if the block was successfully copied. The returned // errors is *only* non-nil for errors that are fatal for pulling this entire // file (i.e. writing to dstFd fails). For other errors that mean the block // wasn't copied, but we can continue trying, the error is nil and the bool