From b34edb0d3b3f524498f8bbea92089ed4124143ec Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 10 Feb 2024 10:07:40 +0000 Subject: [PATCH] Adjustments to profile saving logging logic Bundle up profile save time and display in one line + do not log to file Don't log when each profile is saved Do not log to file how much fuel is left in generator --- project/src/helpers/HideoutHelper.ts | 3 ++- project/src/servers/SaveServer.ts | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/project/src/helpers/HideoutHelper.ts b/project/src/helpers/HideoutHelper.ts index 356dd15d..b2bc214e 100644 --- a/project/src/helpers/HideoutHelper.ts +++ b/project/src/helpers/HideoutHelper.ts @@ -487,7 +487,8 @@ export class HideoutHelper fuelItemInSlot.upd = this.getAreaUpdObject(1, fuelRemaining, pointsConsumed); this.logger.debug( - `$Profile: ${pmcData._id} Generator has: ${fuelRemaining} fuel left in slot ${i + 1}`, + `Profile: ${pmcData._id} Generator has: ${fuelRemaining} fuel left in slot ${i + 1}`, + true, ); hasFuelRemaining = true; diff --git a/project/src/servers/SaveServer.ts b/project/src/servers/SaveServer.ts index d27b41f6..8250769c 100644 --- a/project/src/servers/SaveServer.ts +++ b/project/src/servers/SaveServer.ts @@ -79,10 +79,13 @@ export class SaveServer public save(): void { // Save every profile + let totalTime = 0; for (const sessionID in this.profiles) { - this.saveProfile(sessionID); + totalTime += this.saveProfile(sessionID); } + + this.logger.debug(`Saved ${Object.keys(this.profiles).length} profiles, took: ${totalTime.toFixed(2)}ms`, true); } /** @@ -172,7 +175,7 @@ export class SaveServer // File found, store in profiles[] const start = performance.now(); this.profiles[sessionID] = this.jsonUtil.deserialize(this.vfs.readFile(filePath), filename); - this.logger.debug(`Profile ${sessionID} took ${performance.now() - start}ms to load.`); + this.logger.debug(`Profile: ${sessionID} took: ${performance.now() - start}ms to load.`, true); } // Run callbacks @@ -186,8 +189,9 @@ export class SaveServer * Save changes from in-memory profile to user/profiles json * Execute onBeforeSaveCallbacks callbacks prior to being saved to json * @param sessionID profile id (user/profiles/id.json) + * @returns time taken to save in MS */ - public saveProfile(sessionID: string): void + public saveProfile(sessionID: string): number { const filePath = `${this.profileFilepath}${sessionID}.json`; @@ -217,9 +221,9 @@ export class SaveServer this.saveMd5[sessionID] = String(fmd5); // save profile to disk this.vfs.writeFile(filePath, jsonProfile); - this.logger.debug(this.localisationService.getText("profile_saved", sessionID), true); } - this.logger.debug(`Profile ${sessionID} took ${performance.now() - start}ms to save.`); + + return Number(performance.now() - start); } /**