From fd56123acf0912013cb9c258f7dbc544ae476e01 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 30 Dec 2013 22:05:00 -0500 Subject: [PATCH] Send index in chunks of 1000 to avoid lengthy blocking --- model.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/model.go b/model.go index 619c1d9c0..0a8ab068f 100644 --- a/model.go +++ b/model.go @@ -468,13 +468,16 @@ func (m *Model) AddNode(node *protocol.Connection) { idx := m.protocolIndex() m.RUnlock() - if opts.Debug.TraceNet { - debugf("NET IDX(out/add): %s: %d files", node.ID, len(idx)) + for i := 0; i < len(idx); i += 1000 { + s := i + 1000 + if s > len(idx) { + s = len(idx) + } + if opts.Debug.TraceNet { + debugf("NET IDX(out/add): %s: %d:%d", node.ID, i, s) + } + node.Index(idx[i:s]) } - - // Sending the index might take a while if we have many files and a slow - // uplink. Return from AddNode in the meantime. - go node.Index(idx) } func fileFromFileInfo(f protocol.FileInfo) File {