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

View File

@@ -7,6 +7,7 @@ import {
onComplete,
onStart,
} from '@toeverything/infra';
import { isEqual } from 'lodash-es';
import { EMPTY, exhaustMap, mergeMap } from 'rxjs';
import { validateAndReduceImage } from '../../../utils/reduce-image';
@@ -73,7 +74,9 @@ export class AuthSession extends Entity {
count: Infinity,
}),
mergeMap(sessionInfo => {
this.store.setCachedAuthSession(sessionInfo);
if (!isEqual(this.store.getCachedAuthSession(), sessionInfo)) {
this.store.setCachedAuthSession(sessionInfo);
}
return EMPTY;
}),
onStart(() => {

View File

@@ -32,6 +32,10 @@ export class AuthStore extends Store {
return this.globalState.watch<AuthSessionInfo>('affine-cloud-auth');
}
getCachedAuthSession() {
return this.globalState.get<AuthSessionInfo>('affine-cloud-auth');
}
setCachedAuthSession(session: AuthSessionInfo | null) {
this.globalState.set('affine-cloud-auth', session);
}