From 69eccc706593935395d362677b3219321c6eb853 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Sat, 6 Jan 2024 21:07:03 +0100 Subject: xP: don't let buffers grow indefinitely Primarily for performance reasons. --- xP/public/xP.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/xP/public/xP.js b/xP/public/xP.js index e4f5647..ea70bbd 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -197,6 +197,14 @@ function bufferResetStats(b) { 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) { 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. if (bufferCurrent === undefined) { b.lines.push(line) + bufferPopExcessLines(b) return } @@ -293,6 +302,7 @@ rpcEventHandlers.set(Relay.Event.BufferLine, e => { else b.newMessages++ } + bufferPopExcessLines(b) if (e.leakToActive) { let bc = buffers.get(bufferCurrent) @@ -303,6 +313,7 @@ rpcEventHandlers.set(Relay.Event.BufferLine, e => { else bc.newMessages++ } + bufferPopExcessLines(bc) } if (line.isHighlight || (!visible && !line.isUnimportant && @@ -336,7 +347,7 @@ rpcEventHandlers.set(Relay.Event.BufferStats, e => { if (b === undefined) return - b.newMessages = e.newMessages, + b.newMessages = e.newMessages b.newUnimportantMessages = e.newUnimportantMessages b.highlighted = e.highlighted }) -- cgit v1.2.3-70-g09d2