mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-19 04:35:46 +01:00
PERFORMANCE: Improve speed of saving when there are lots of scripts (#430)
This commit is contained in:
parent
be5bba8ad6
commit
c77b89d4d9
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user