Skip to content

Commit b1cc999

Browse files
committed
fix: clear version check cache on channel switch to avoid stale notifications
1 parent 80e198f commit b1cc999

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/lib/db/release-channel.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import { getDatabase } from "./index.js";
1313
import { runUpsert } from "./utils.js";
14+
import { clearVersionCheckCache } from "./version-check.js";
1415

1516
const KEY = "release_channel";
1617

@@ -37,11 +38,19 @@ export function getReleaseChannel(): ReleaseChannel {
3738
/**
3839
* Persist the release channel.
3940
*
41+
* If the channel has changed, the cached version-check result is also cleared
42+
* so the next notification does not display a stale version from the old channel
43+
* (e.g. a cached stable version labelled as a nightly update after switching).
44+
*
4045
* @param channel - Channel to store
4146
*/
4247
export function setReleaseChannel(channel: ReleaseChannel): void {
4348
const db = getDatabase();
49+
const current = getReleaseChannel();
4450
runUpsert(db, "metadata", { key: KEY, value: channel }, ["key"]);
51+
if (channel !== current) {
52+
clearVersionCheckCache();
53+
}
4554
}
4655

4756
/**

src/lib/db/version-check.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ export function getVersionCheckInfo(): VersionCheckInfo {
3838
};
3939
}
4040

41+
/**
42+
* Clear the cached latest version.
43+
*
44+
* Should be called when the release channel changes so that stale version
45+
* data from the previous channel is not shown in update notifications.
46+
* The last-checked timestamp is also reset so a fresh check is triggered
47+
* on the next CLI invocation.
48+
*/
49+
export function clearVersionCheckCache(): void {
50+
const db = getDatabase();
51+
db.query("DELETE FROM metadata WHERE key = ? OR key = ?").run(
52+
KEY_LAST_CHECKED,
53+
KEY_LATEST_VERSION
54+
);
55+
}
56+
4157
/**
4258
* Store the version check result.
4359
* Updates both the last checked timestamp and the latest known version.

0 commit comments

Comments
 (0)