From 7ad73b408adc792cabeed41d89a37b93e2bd84d0 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sun, 4 Oct 2026 08:16:09 +0200 Subject: [PATCH] fix: remove unnecessary delay in index transmission (#10908) Prior to refactoring, this delay kicked in once all batches were sent. Now, it came between each batch. Fix that. --------- Signed-off-by: Jakob Borg --- lib/model/indexhandler.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/model/indexhandler.go b/lib/model/indexhandler.go index 4e1606780..85429abfe 100644 --- a/lib/model/indexhandler.go +++ b/lib/model/indexhandler.go @@ -183,7 +183,7 @@ func (s *indexHandler) Serve(ctx context.Context) (err error) { if err := s.waitWhilePaused(ctx); err != nil { return err } - err = s.sendIndexTo(ctx) + err = s.sendIndexBatch(ctx) // Subscribe to LocalIndexUpdated (we have new information to send) and // DeviceDisconnected (it might be us who disconnected, so we should @@ -214,21 +214,14 @@ func (s *indexHandler) Serve(ctx context.Context) (err error) { case <-ctx.Done(): return ctx.Err() case <-evChan: + // Consolidate possibly multiple index changes + time.Sleep(250 * time.Millisecond) case <-ticker.C: } continue } - err = s.sendIndexTo(ctx) - - // Wait a short amount of time before entering the next loop. If there - // are continuous changes happening to the local index, this gives us - // time to batch them up a little. - select { - case <-ctx.Done(): - return ctx.Err() - case <-time.After(250 * time.Millisecond): - } + err = s.sendIndexBatch(ctx) } return err @@ -255,9 +248,8 @@ func (s *indexHandler) pause() { s.cond.L.Unlock() } -// sendIndexTo sends file infos with a sequence number higher than prevSequence and -// returns the highest sent sequence number. -func (s *indexHandler) sendIndexTo(ctx context.Context) error { +// sendIndexBatch sends one batch of index data. +func (s *indexHandler) sendIndexBatch(ctx context.Context) error { initial := s.localPrevSequence == 0 batch := NewFileInfoBatch(nil) var batchError error