PERFORMANCE: Improve speed of saving when there are lots of scripts (#430)

This commit is contained in:
David Walker 2023-03-17 20:59:27 -07:00 committed by GitHub
parent be5bba8ad6
commit c77b89d4d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -199,20 +199,20 @@ export function loadAllServers(saveString: string): void {
AllServers = JSON.parse(saveString, Reviver);
}
export function saveAllServers(excludeRunningScripts = false): string {
const TempAllServers = JSON.parse(JSON.stringify(AllServers), Reviver);
for (const key of Object.keys(TempAllServers)) {
const server = TempAllServers[key];
if (excludeRunningScripts) {
server.runningScripts = [];
continue;
}
for (let i = 0; i < server.runningScripts.length; ++i) {
const runningScriptObj = server.runningScripts[i];
runningScriptObj.logs.length = 0;
runningScriptObj.logs = [];
}
function excludeReplacer(key: string, value: any): any {
if (key === "runningScripts") {
return [];
}
return JSON.stringify(TempAllServers);
return value;
}
function includeReplacer(key: string, value: any): any {
if (key === "logs") {
return [];
}
return value;
}
export function saveAllServers(excludeRunningScripts = false): string {
return JSON.stringify(AllServers, excludeRunningScripts ? excludeReplacer : includeReplacer);
}