mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 15:17:25 +00:00
Merge pull request #1648 from calmh/scanner-batches
Don't buffer large files a long time while scanning
This commit is contained in:
commit
a624c302ab
@ -1194,18 +1194,24 @@ nextSub:
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
batchSize := 100
|
batchSizeFiles := 100
|
||||||
batch := make([]protocol.FileInfo, 0, batchSize)
|
batchSizeBlocks := 2048 // about 256 MB
|
||||||
|
|
||||||
|
batch := make([]protocol.FileInfo, 0, batchSizeFiles)
|
||||||
|
blocksHandled := 0
|
||||||
|
|
||||||
for f := range fchan {
|
for f := range fchan {
|
||||||
if len(batch) == batchSize {
|
if len(batch) == batchSizeFiles || blocksHandled > batchSizeBlocks {
|
||||||
if err := m.CheckFolderHealth(folder); err != nil {
|
if err := m.CheckFolderHealth(folder); err != nil {
|
||||||
l.Infof("Stopping folder %s mid-scan due to folder error: %s", folder, err)
|
l.Infof("Stopping folder %s mid-scan due to folder error: %s", folder, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
m.updateLocals(folder, batch)
|
m.updateLocals(folder, batch)
|
||||||
batch = batch[:0]
|
batch = batch[:0]
|
||||||
|
blocksHandled = 0
|
||||||
}
|
}
|
||||||
batch = append(batch, f)
|
batch = append(batch, f)
|
||||||
|
blocksHandled += len(f.Blocks)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.CheckFolderHealth(folder); err != nil {
|
if err := m.CheckFolderHealth(folder); err != nil {
|
||||||
@ -1240,7 +1246,7 @@ nextSub:
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(batch) == batchSize {
|
if len(batch) == batchSizeFiles {
|
||||||
m.updateLocals(folder, batch)
|
m.updateLocals(folder, batch)
|
||||||
batch = batch[:0]
|
batch = batch[:0]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user