Ver código fonte

lib/model: Use same batch size constants in db updater as for protocol

Jakob Borg 8 anos atrás
pai
commit
e33fa10115
1 arquivos alterados com 7 adições e 7 exclusões
  1. 7 7
      lib/model/rwfolder.go

+ 7 - 7
lib/model/rwfolder.go

@@ -1479,13 +1479,10 @@ func (f *sendReceiveFolder) Jobs() ([]string, []string) {
 // dbUpdaterRoutine aggregates db updates and commits them in batches no
 // larger than 1000 items, and no more delayed than 2 seconds.
 func (f *sendReceiveFolder) dbUpdaterRoutine() {
-	const (
-		maxBatchSize = 1000
-		maxBatchTime = 2 * time.Second
-	)
+	const maxBatchTime = 2 * time.Second
 
-	batch := make([]dbUpdateJob, 0, maxBatchSize)
-	files := make([]protocol.FileInfo, 0, maxBatchSize)
+	batch := make([]dbUpdateJob, 0, maxBatchSizeFiles)
+	files := make([]protocol.FileInfo, 0, maxBatchSizeFiles)
 	tick := time.NewTicker(maxBatchTime)
 	defer tick.Stop()
 
@@ -1545,6 +1542,7 @@ func (f *sendReceiveFolder) dbUpdaterRoutine() {
 		files = files[:0]
 	}
 
+	batchSizeBytes := 0
 loop:
 	for {
 		select {
@@ -1556,8 +1554,10 @@ loop:
 			job.file.Sequence = 0
 			batch = append(batch, job)
 
-			if len(batch) == maxBatchSize {
+			batchSizeBytes += job.file.ProtoSize()
+			if len(batch) == maxBatchSizeFiles || batchSizeBytes > maxBatchSizeBytes {
 				handleBatch()
+				batchSizeBytes = 0
 			}
 
 		case <-tick.C: