From 6dc868154dea4a30ce8733844280c0b0dc8bc7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=87=E6=A2=A6=E4=BA=BA?= Date: Thu, 5 Sep 2024 21:52:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E4=BA=91=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BD=BFaccess=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=8C=89=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E5=90=88?= =?UTF-8?q?=E5=B9=B6=EF=BC=8C=E8=A7=A3=E5=86=B3=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E9=85=8D=E7=BD=AE=E5=9C=A8=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=90=8E=E4=B8=A2=E5=A4=B1=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/access.ts | 2 +- app/utils/sync.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/store/access.ts b/app/store/access.ts index b89b080d8..30f8ce146 100644 --- a/app/store/access.ts +++ b/app/store/access.ts @@ -210,7 +210,7 @@ export const useAccessStore = createPersistStore( }) .then((res: DangerConfig) => { console.log("[Config] got config from server", res); - set(() => ({ ...res })); + set(() => ({ lastUpdateTime: Date.now(), ...res })); }) .catch(() => { console.error("[Config] failed to fetch config"); diff --git a/app/utils/sync.ts b/app/utils/sync.ts index 645d8ac11..fed030679 100644 --- a/app/utils/sync.ts +++ b/app/utils/sync.ts @@ -128,7 +128,13 @@ const MergeStates: StateMerger = { }); const remoteDeletedSessionIds = remoteState.deletedSessionIds || {}; + + const finalIds: Record = {}; localState.sessions = localState.sessions.filter((localSession) => { + if (finalIds[localSession.id]) { + return false; + } + finalIds[localSession.id] = true; return ( (remoteDeletedSessionIds[localSession.id] || -1) <= localSession.lastUpdate @@ -209,9 +215,9 @@ export function mergeWithUpdate( remoteState: T, ) { const localUpdateTime = localState.lastUpdateTime ?? 0; - const remoteUpdateTime = localState.lastUpdateTime ?? 1; + const remoteUpdateTime = remoteState.lastUpdateTime ?? 1; - if (localUpdateTime < remoteUpdateTime) { + if (localUpdateTime >= remoteUpdateTime) { merge(remoteState, localState); return { ...remoteState }; } else {