xP: don't let buffers grow indefinitely

Primarily for performance reasons.
This commit is contained in:
Přemysl Eric Janouch 2024-01-06 21:07:03 +01:00
parent 13d2ff115b
commit 69eccc7065
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 12 additions and 1 deletions

View File

@ -197,6 +197,14 @@ function bufferResetStats(b) {
b.highlighted = false b.highlighted = false
} }
function bufferPopExcessLines(b) {
// Let "new" messages be, if only because pulling the log file
// is much more problematic in the web browser than in xC.
// TODO: Make the limit configurable, or extract general.backlog_limit.
const old = b.lines.length - b.newMessages - b.newUnimportantMessages
b.lines.splice(0, old - 1000)
}
function bufferActivate(name) { function bufferActivate(name) {
rpc.send({command: 'BufferActivate', bufferName: name}) rpc.send({command: 'BufferActivate', bufferName: name})
} }
@ -278,6 +286,7 @@ rpcEventHandlers.set(Relay.Event.BufferLine, e => {
// Initial sync: skip all other processing, let highlights be. // Initial sync: skip all other processing, let highlights be.
if (bufferCurrent === undefined) { if (bufferCurrent === undefined) {
b.lines.push(line) b.lines.push(line)
bufferPopExcessLines(b)
return return
} }
@ -293,6 +302,7 @@ rpcEventHandlers.set(Relay.Event.BufferLine, e => {
else else
b.newMessages++ b.newMessages++
} }
bufferPopExcessLines(b)
if (e.leakToActive) { if (e.leakToActive) {
let bc = buffers.get(bufferCurrent) let bc = buffers.get(bufferCurrent)
@ -303,6 +313,7 @@ rpcEventHandlers.set(Relay.Event.BufferLine, e => {
else else
bc.newMessages++ bc.newMessages++
} }
bufferPopExcessLines(bc)
} }
if (line.isHighlight || (!visible && !line.isUnimportant && if (line.isHighlight || (!visible && !line.isUnimportant &&
@ -336,7 +347,7 @@ rpcEventHandlers.set(Relay.Event.BufferStats, e => {
if (b === undefined) if (b === undefined)
return return
b.newMessages = e.newMessages, b.newMessages = e.newMessages
b.newUnimportantMessages = e.newUnimportantMessages b.newUnimportantMessages = e.newUnimportantMessages
b.highlighted = e.highlighted b.highlighted = e.highlighted
}) })