diff options
| author | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2026-07-07 12:32:15 +0200 |
|---|---|---|
| committer | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2026-07-07 12:32:15 +0200 |
| commit | 85301b69f478c34e3ee7488f5b04ae4ac5b3ba1e (patch) | |
| tree | 8ce845908ced04235a140c8cb231dc6cb672bd0a /cmd_windows.go | |
| parent | 1bcc79fc8d6d91a26a744bcab9fd1b661e0466d2 (diff) | |
| download | sourcewatch-85301b69f478c34e3ee7488f5b04ae4ac5b3ba1e.tar.gz sourcewatch-85301b69f478c34e3ee7488f5b04ae4ac5b3ba1e.zip | |
Chunk manifest transfer: 1000 files per batch
Avoids bufio.Scanner token limit by sending manifest in batches.
Each batch is a separate JSON line with up to 1000 files.
Diffstat (limited to 'cmd_windows.go')
| -rw-r--r-- | cmd_windows.go | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/cmd_windows.go b/cmd_windows.go index 7df0a9b..dfe137a 100644 --- a/cmd_windows.go +++ b/cmd_windows.go @@ -275,16 +275,42 @@ func scanDirectory(root string, stack *GitignoreStack) *Manifest { } func sendManifest(conn net.Conn, manifest *Manifest) { - msg := &ProtocolMessage{ - Type: "manifest", - Files: manifest.ToJSON(), + const batchSize = 1000 + files := make([]FileMetaJSON, 0, batchSize) + paths := make([]string, 0, batchSize) + + for path, meta := range manifest.ToJSON() { + paths = append(paths, path) + files = append(files, meta) + + if len(files) >= batchSize { + msg := &ProtocolMessage{ + Type: "manifest_batch", + Files: make(map[string]FileMetaJSON), + } + for i, p := range paths { + msg.Files[p] = files[i] + } + data, _ := EncodeMessage(msg) + data = append(data, '\n') + conn.Write(data) + files = files[:0] + paths = paths[:0] + } } - data, err := EncodeMessage(msg) - if err != nil { - return + + if len(files) > 0 { + msg := &ProtocolMessage{ + Type: "manifest_batch", + Files: make(map[string]FileMetaJSON), + } + for i, p := range paths { + msg.Files[p] = files[i] + } + data, _ := EncodeMessage(msg) + data = append(data, '\n') + conn.Write(data) } - data = append(data, '\n') - conn.Write(data) done := &ProtocolMessage{Type: "manifest_done"} doneData, _ := EncodeMessage(done) |
