Skip to content

Commit 6dc8681

Browse files
committed
fix: 优化云同步功能,使access配置按更新时间合并,解决自定义模型配置在同步后丢失的问题
1 parent ccacfec commit 6dc8681

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

app/store/access.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export const useAccessStore = createPersistStore(
210210
})
211211
.then((res: DangerConfig) => {
212212
console.log("[Config] got config from server", res);
213-
set(() => ({ ...res }));
213+
set(() => ({ lastUpdateTime: Date.now(), ...res }));
214214
})
215215
.catch(() => {
216216
console.error("[Config] failed to fetch config");

app/utils/sync.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@ const MergeStates: StateMerger = {
128128
});
129129

130130
const remoteDeletedSessionIds = remoteState.deletedSessionIds || {};
131+
132+
const finalIds: Record<string, any> = {};
131133
localState.sessions = localState.sessions.filter((localSession) => {
134+
if (finalIds[localSession.id]) {
135+
return false;
136+
}
137+
finalIds[localSession.id] = true;
132138
return (
133139
(remoteDeletedSessionIds[localSession.id] || -1) <=
134140
localSession.lastUpdate
@@ -209,9 +215,9 @@ export function mergeWithUpdate<T extends { lastUpdateTime?: number }>(
209215
remoteState: T,
210216
) {
211217
const localUpdateTime = localState.lastUpdateTime ?? 0;
212-
const remoteUpdateTime = localState.lastUpdateTime ?? 1;
218+
const remoteUpdateTime = remoteState.lastUpdateTime ?? 1;
213219

214-
if (localUpdateTime < remoteUpdateTime) {
220+
if (localUpdateTime >= remoteUpdateTime) {
215221
merge(remoteState, localState);
216222
return { ...remoteState };
217223
} else {

0 commit comments

Comments
 (0)