mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-26 09:20:18 +08:00
perf(安装日志): 优化安装日志处理性能
添加日志缓冲和批量发送机制以减少IPC通信次数 限制前端日志条目数量防止内存泄漏
This commit is contained in:
@@ -561,20 +561,42 @@ async function processNextInQueue() {
|
|||||||
|
|
||||||
let stdout = "";
|
let stdout = "";
|
||||||
let stderr = "";
|
let stderr = "";
|
||||||
|
let logBuffer = "";
|
||||||
|
let logBufferTimer: NodeJS.Timeout | null = null;
|
||||||
|
const LOG_FLUSH_MS = 100;
|
||||||
|
|
||||||
|
const flushLogBuffer = () => {
|
||||||
|
if (logBuffer.length > 0) {
|
||||||
|
sendLog(logBuffer);
|
||||||
|
logBuffer = "";
|
||||||
|
}
|
||||||
|
logBufferTimer = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const bufferedSendLog = (message: string) => {
|
||||||
|
logBuffer += message;
|
||||||
|
if (!logBufferTimer) {
|
||||||
|
logBufferTimer = setTimeout(flushLogBuffer, LOG_FLUSH_MS);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
child.stdout.on("data", (d) => {
|
child.stdout.on("data", (d) => {
|
||||||
const s = d.toString();
|
const s = d.toString();
|
||||||
stdout += s;
|
stdout += s;
|
||||||
sendLog(s);
|
bufferedSendLog(s);
|
||||||
});
|
});
|
||||||
|
|
||||||
child.stderr.on("data", (d) => {
|
child.stderr.on("data", (d) => {
|
||||||
const s = d.toString();
|
const s = d.toString();
|
||||||
stderr += s;
|
stderr += s;
|
||||||
sendLog(s);
|
bufferedSendLog(s);
|
||||||
});
|
});
|
||||||
|
|
||||||
child.on("close", (code) => {
|
child.on("close", (code) => {
|
||||||
|
if (logBufferTimer) {
|
||||||
|
clearTimeout(logBufferTimer);
|
||||||
|
flushLogBuffer();
|
||||||
|
}
|
||||||
if (task.cancelled) {
|
if (task.cancelled) {
|
||||||
reject(new Error("安装已取消"));
|
reject(new Error("安装已取消"));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -183,13 +183,19 @@ window.ipcRenderer.on(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const MAX_LOG_ENTRIES = 500;
|
||||||
|
|
||||||
window.ipcRenderer.on("install-log", (_event, log: InstallLog) => {
|
window.ipcRenderer.on("install-log", (_event, log: InstallLog) => {
|
||||||
const downloadObj = downloads.value.find((d) => d.id === log.id);
|
const downloadObj = downloads.value.find((d) => d.id === log.id);
|
||||||
if (downloadObj)
|
if (downloadObj) {
|
||||||
downloadObj.logs.push({
|
downloadObj.logs.push({
|
||||||
time: log.time,
|
time: log.time,
|
||||||
message: log.message,
|
message: log.message,
|
||||||
});
|
});
|
||||||
|
if (downloadObj.logs.length > MAX_LOG_ENTRIES) {
|
||||||
|
downloadObj.logs.splice(0, downloadObj.logs.length - MAX_LOG_ENTRIES);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
window.ipcRenderer.on("install-complete", (_event, log: DownloadResult) => {
|
window.ipcRenderer.on("install-complete", (_event, log: DownloadResult) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user