mirror of
https://github.com/syncthing/syncthing.git
synced 2026-11-26 03:46:34 -08:00
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 <[email protected]>
This commit is contained in:
1 parent
05b6704ef5
commit
7ad73b408a
1 file changed
+6
-14
@@ -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
|
||||
|
||||
Reference in new issue
Block a user