utils: fix radb fetching lines too long for scanner buffer size, allow caching empty results

This commit is contained in:
WeebDataHoarder
2025-04-27 22:04:21 +02:00
parent b285c13e4c
commit b8bf35d4de
2 changed files with 9 additions and 1 deletions

View File

@@ -53,6 +53,9 @@ func (db *RADb) query(fn func(n int, record []byte) error, queries ...string) er
scanner := bufio.NewScanner(conn)
scanner.Split(bufio.ScanLines)
// 16 MiB lines
const bufferSize = 1024 * 1024 * 16
scanner.Buffer(make([]byte, 0, bufferSize), bufferSize)
for _, q := range queries {
@@ -66,6 +69,7 @@ func (db *RADb) query(fn func(n int, record []byte) error, queries ...string) er
for scanner.Scan() {
buf := bytes.Trim(scanner.Bytes(), "\r\n")
fmt.Println(string(buf))
if bytes.HasPrefix(buf, []byte("%")) || bytes.Equal(buf, []byte("C")) {
// end of record
break
@@ -76,6 +80,10 @@ func (db *RADb) query(fn func(n int, record []byte) error, queries ...string) er
}
n++
}
if scanner.Err() != nil {
return scanner.Err()
}
}
if len(queries) > 1 {