fix: 优化云同步功能,使access配置按更新时间合并,解决自定义模型配置在同步后丢失的问题
This commit is contained in:
parent
ccacfec918
commit
6dc868154d
|
@ -210,7 +210,7 @@ export const useAccessStore = createPersistStore(
|
||||||
})
|
})
|
||||||
.then((res: DangerConfig) => {
|
.then((res: DangerConfig) => {
|
||||||
console.log("[Config] got config from server", res);
|
console.log("[Config] got config from server", res);
|
||||||
set(() => ({ ...res }));
|
set(() => ({ lastUpdateTime: Date.now(), ...res }));
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
console.error("[Config] failed to fetch config");
|
console.error("[Config] failed to fetch config");
|
||||||
|
|
|
@ -128,7 +128,13 @@ const MergeStates: StateMerger = {
|
||||||
});
|
});
|
||||||
|
|
||||||
const remoteDeletedSessionIds = remoteState.deletedSessionIds || {};
|
const remoteDeletedSessionIds = remoteState.deletedSessionIds || {};
|
||||||
|
|
||||||
|
const finalIds: Record<string, any> = {};
|
||||||
localState.sessions = localState.sessions.filter((localSession) => {
|
localState.sessions = localState.sessions.filter((localSession) => {
|
||||||
|
if (finalIds[localSession.id]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finalIds[localSession.id] = true;
|
||||||
return (
|
return (
|
||||||
(remoteDeletedSessionIds[localSession.id] || -1) <=
|
(remoteDeletedSessionIds[localSession.id] || -1) <=
|
||||||
localSession.lastUpdate
|
localSession.lastUpdate
|
||||||
|
@ -209,9 +215,9 @@ export function mergeWithUpdate<T extends { lastUpdateTime?: number }>(
|
||||||
remoteState: T,
|
remoteState: T,
|
||||||
) {
|
) {
|
||||||
const localUpdateTime = localState.lastUpdateTime ?? 0;
|
const localUpdateTime = localState.lastUpdateTime ?? 0;
|
||||||
const remoteUpdateTime = localState.lastUpdateTime ?? 1;
|
const remoteUpdateTime = remoteState.lastUpdateTime ?? 1;
|
||||||
|
|
||||||
if (localUpdateTime < remoteUpdateTime) {
|
if (localUpdateTime >= remoteUpdateTime) {
|
||||||
merge(remoteState, localState);
|
merge(remoteState, localState);
|
||||||
return { ...remoteState };
|
return { ...remoteState };
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue