speed up admin ui polling and payloads
This commit is contained in:
+10
-3
@@ -1117,7 +1117,8 @@ function buildLogsSnapshot(monitor, sinceSeq = null) {
|
||||
};
|
||||
}
|
||||
|
||||
async function buildPersistentLogsSnapshot(runtime, sinceSeq = null) {
|
||||
async function buildPersistentLogsSnapshot(runtime, sinceSeq = null, limit = 500) {
|
||||
const safeLimit = Number.isInteger(limit) && limit > 0 ? Math.min(limit, 1000) : 500;
|
||||
const text = runtime.logPath ? await readOptionalText(runtime.logPath) : null;
|
||||
if (!text) {
|
||||
return buildLogsSnapshot(runtime.monitor, sinceSeq);
|
||||
@@ -1129,7 +1130,7 @@ async function buildPersistentLogsSnapshot(runtime, sinceSeq = null) {
|
||||
.map((line, index) => parseLogLine(line, index + 1));
|
||||
const entries = Number.isInteger(sinceSeq)
|
||||
? allEntries.filter((entry) => entry.seq > sinceSeq)
|
||||
: allEntries.slice(-500);
|
||||
: allEntries.slice(-safeLimit);
|
||||
|
||||
return {
|
||||
total_entries: allEntries.length,
|
||||
@@ -1945,10 +1946,16 @@ async function handleManagementRequest(runtime, req, res, requestUrl) {
|
||||
|
||||
if (pathname === LOGS_API_PATH && req.method === "GET") {
|
||||
const sinceSeqRaw = requestUrl.searchParams.get("since_seq");
|
||||
const limitRaw = requestUrl.searchParams.get("limit");
|
||||
const sinceSeq = sinceSeqRaw === null ? null : Number.parseInt(sinceSeqRaw, 10);
|
||||
const limit = limitRaw === null ? 500 : Number.parseInt(limitRaw, 10);
|
||||
jsonResponse(res, 200, {
|
||||
ok: true,
|
||||
...await buildPersistentLogsSnapshot(runtime, Number.isInteger(sinceSeq) ? sinceSeq : null),
|
||||
...await buildPersistentLogsSnapshot(
|
||||
runtime,
|
||||
Number.isInteger(sinceSeq) ? sinceSeq : null,
|
||||
Number.isInteger(limit) ? limit : 500,
|
||||
),
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user