From 232e11084f5c9aa16a1f4011c7956618a70d2dca Mon Sep 17 00:00:00 2001 From: renxia Date: Thu, 26 Dec 2024 17:56:00 +0800 Subject: [PATCH] =?UTF-8?q?perf(LiteStorage):=20save=20=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=97=B6=E8=8B=A5=E6=97=A0=E6=95=B0=E6=8D=AE=E5=8F=98=E6=9B=B4?= =?UTF-8?q?=E5=88=99=E5=BF=BD=E7=95=A5=E5=86=99=E6=96=87=E4=BB=B6=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/node/LiteStorage.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/node/LiteStorage.ts b/src/node/LiteStorage.ts index 98ab0f8..96023e7 100644 --- a/src/node/LiteStorage.ts +++ b/src/node/LiteStorage.ts @@ -53,6 +53,7 @@ export class LiteStorage> { private barrier = new Barrier(); private isToml = false; private isJson5 = false; + private isChanged = false; // @ts-ignore private cache: LSCache; @@ -97,6 +98,7 @@ export class LiteStorage> { /** 主动保存 */ public async save(value?: T, mode: 'merge' | 'cover' = 'merge') { if (value) return this.set(value, mode); + if (!this.isChanged) return this; await this.reload(); return this.toCache(); } @@ -143,6 +145,7 @@ export class LiteStorage> { if (mode === 'merge') assign(this.cache.data[uuid], value); else this.cache.data[uuid] = value; } + this.isChanged = true; this.save(); } else { console.warn('[LiteStorage][set]error', uuid, value);