25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(redis): 优化自动刷新逻辑和显示TTL的计算
二丫讲梵92b42d559df1
diff --git a/apps/desktop/src/lib/__tests__/redis/redisAutoRefresh.spec.ts b/apps/desktop/src/lib/__tests__/redis/redisAutoRefresh.spec.tsindex 628dce439c..c787da6649 100644--- a/apps/desktop/src/lib/__tests__/redis/redisAutoRefresh.spec.ts+++ b/apps/desktop/src/lib/__tests__/redis/redisAutoRefresh.spec.ts@@ -10,19 +10,20 @@ describe("computeAutoRefreshTick", () => {expect(computeAutoRefreshTick(false, 5, true)).toEqual({ type: "idle" });});- it("returns decrement when countdown is above zero", () => {+ it("returns decrement while more than one second remains", () => {expect(computeAutoRefreshTick(true, 10, false)).toEqual({ type: "decrement" });- expect(computeAutoRefreshTick(true, 1, false)).toEqual({ type: "decrement" });// decrement even when loading — countdown should keep tickingexpect(computeAutoRefreshTick(true, 3, true)).toEqual({ type: "decrement" });});- it("returns refresh when countdown reaches zero and not loading", () => {+ it("refreshes on the expiry tick instead of exposing a zero countdown", () => {+ expect(computeAutoRefreshTick(true, 1, false)).toEqual({ type: "refresh" });expect(computeAutoRefreshTick(true, 0, false)).toEqual({ type: "refresh" });expect(computeAutoRefreshTick(true, -1, false)).toEqual({ type: "refresh" });});- it("returns idle when countdown is zero but a load is already in flight", () => {+ it("does not start another refresh when a load is already in flight", () => {+ expect(computeAutoRefreshTick(true, 1, true)).toEqual({ type: "decrement" });// This prevents concurrent load() callsexpect(computeAutoRefreshTick(true, 0, true)).toEqual({ type: "idle" });expect(computeAutoRefreshTick(true, -1, true)).toEqual({ type: "idle" });@@ -50,9 +51,8 @@ describe("computeDisplayTtl", () => {expect(computeDisplayTtl(false, 3, 10)).toBe(10);});- it("returns server TTL when countdown has not started (zero)", () => {- // countdownTtl starts at 0 before first tick; show server TTL- expect(computeDisplayTtl(true, 0, 10)).toBe(10);+ it("does not flash back to the stale server TTL at zero", () => {+ expect(computeDisplayTtl(true, 0, 5)).toBe(0);});it("returns live countdown when auto-refresh is active and counting", () => {@@ -60,9 +60,7 @@ describe("computeDisplayTtl", () => {expect(computeDisplayTtl(true, 1, 10)).toBe(1);});- it("returns server TTL when countdown would go below zero", () => {- // Edge case: countdownTtl shouldn't be negative in practice,- // but if it is, fall back to server TTL- expect(computeDisplayTtl(true, -1, 10)).toBe(10);+ it("clamps an active countdown below zero instead of showing stale data", () => {+ expect(computeDisplayTtl(true, -1, 10)).toBe(0);});});diff --git a/apps/desktop/src/lib/redis/redisAutoRefresh.ts b/apps/desktop/src/lib/redis/redisAutoRefresh.tsindex 683a19f201..ae8eff91fa 100644--- a/apps/desktop/src/lib/redis/redisAutoRefresh.ts+++ b/apps/desktop/src/lib/redis/redisAutoRefresh.ts@@ -18,9 +18,8 @@ export type AutoRefreshTickAction = { type: "idle" } | { type: "decrement" } | {*/export function computeAutoRefreshTick(enabled: boolean, countdownTtl: number, isLoading: boolean): AutoRefreshTickAction {if (!enabled) return { type: "idle" };- if (countdownTtl > 0) return { type: "decrement" };- if (countdownTtl <= 0 && !isLoading) return { type: "refresh" };- return { type: "idle" };+ if (isLoading) return countdownTtl > 0 ? { type: "decrement" } : { type: "idle" };+ return countdownTtl <= 1 ? { type: "refresh" } : { type: "decrement" };}/**@@ -36,12 +35,9 @@ export function shouldStopAutoRefresh(ttl: number): boolean {/*** Compute the TTL value that should be displayed in the badge.*- * When auto-refresh is active and countdown is running, the live- * countdown value is shown. Otherwise the last known server TTL is used.+ * When auto-refresh is active, the live countdown value is shown. The+ * last known server TTL must not reappear after the countdown reaches zero.*/export function computeDisplayTtl(autoRefreshEnabled: boolean, countdownTtl: number, serverTtl: number): number {- if (autoRefreshEnabled && countdownTtl > 0) {- return countdownTtl;- }- return serverTtl;+ return autoRefreshEnabled ? Math.max(countdownTtl, 0) : serverTtl;}