From ca20c5cebfb29ca1d019e44d4ea3b1c66d60293b Mon Sep 17 00:00:00 2001 From: root Date: Fri, 17 Jul 2026 06:02:02 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=8C=E6=AD=A5=E5=85=B1=E4=BA=AB?= =?UTF-8?q?=E8=AF=84=E5=88=86=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/account-score-service.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/account-score-service.ts b/src/account-score-service.ts index 1ad1868..1658e71 100644 --- a/src/account-score-service.ts +++ b/src/account-score-service.ts @@ -62,7 +62,14 @@ export class AccountScoreService { } state(): ScoreSnapshot { - return { ...this.snapshot, status: this.inFlight ? "refreshing" : this.snapshot.status }; + if (!this.inFlight && existsSync(this.cachePath)) this.snapshot = this.readCache(); + const nextRefreshAt = this.snapshot.nextRefreshAt ? Date.parse(this.snapshot.nextRefreshAt) : Number.NaN; + const status = this.inFlight + ? "refreshing" + : this.snapshot.status === "ready" && Number.isFinite(nextRefreshAt) && Date.now() > nextRefreshAt + ? "stale" + : this.snapshot.status; + return { ...this.snapshot, status }; } async refresh(): Promise { @@ -119,6 +126,7 @@ export class AccountScoreService { refreshStartedAt: startedAt.toISOString(), error: error instanceof Error ? error.message : String(error), }; + this.writeCache(this.snapshot); return this.snapshot; } } @@ -171,7 +179,7 @@ export class AccountScoreService { if (existsSync(this.cachePath)) { try { const cached = record(JSON.parse(readFileSync(this.cachePath, "utf8"))) as ScoreSnapshot | null; - if (cached) return { ...cached, status: "stale", accounts: mergeAccountScores(records(cached.accounts)) }; + if (cached) return { ...cached, accounts: mergeAccountScores(records(cached.accounts)) }; } catch { // Invalid cache is replaced by the next successful refresh. }