fix(core): reduce state refresh (#8181)

This commit is contained in:
EYHN
2024-09-10 06:21:15 +00:00
parent fb76fdfca3
commit 0cdc486f1f
2 changed files with 8 additions and 1 deletions
@@ -7,6 +7,7 @@ import {
onComplete, onComplete,
onStart, onStart,
} from '@toeverything/infra'; } from '@toeverything/infra';
import { isEqual } from 'lodash-es';
import { EMPTY, exhaustMap, mergeMap } from 'rxjs'; import { EMPTY, exhaustMap, mergeMap } from 'rxjs';
import { validateAndReduceImage } from '../../../utils/reduce-image'; import { validateAndReduceImage } from '../../../utils/reduce-image';
@@ -73,7 +74,9 @@ export class AuthSession extends Entity {
count: Infinity, count: Infinity,
}), }),
mergeMap(sessionInfo => { mergeMap(sessionInfo => {
this.store.setCachedAuthSession(sessionInfo); if (!isEqual(this.store.getCachedAuthSession(), sessionInfo)) {
this.store.setCachedAuthSession(sessionInfo);
}
return EMPTY; return EMPTY;
}), }),
onStart(() => { onStart(() => {
@@ -32,6 +32,10 @@ export class AuthStore extends Store {
return this.globalState.watch<AuthSessionInfo>('affine-cloud-auth'); return this.globalState.watch<AuthSessionInfo>('affine-cloud-auth');
} }
getCachedAuthSession() {
return this.globalState.get<AuthSessionInfo>('affine-cloud-auth');
}
setCachedAuthSession(session: AuthSessionInfo | null) { setCachedAuthSession(session: AuthSessionInfo | null) {
this.globalState.set('affine-cloud-auth', session); this.globalState.set('affine-cloud-auth', session);
} }