There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
feat(core): reduce profile loading time (#6616)
EYHN6a23fe37a712
diff --git a/packages/common/infra/src/modules/workspace/entities/profile.ts b/packages/common/infra/src/modules/workspace/entities/profile.tsindex 0453570e45..da7b9cee41 100644--- a/packages/common/infra/src/modules/workspace/entities/profile.ts+++ b/packages/common/infra/src/modules/workspace/entities/profile.ts@@ -1,8 +1,14 @@import { DebugLogger } from '@affine/debug';-import { catchError, EMPTY, from, mergeMap, switchMap } from 'rxjs';+import { catchError, EMPTY, mergeMap, switchMap } from 'rxjs';import { Entity } from '../../../framework';-import { effect, LiveData, onComplete, onStart } from '../../../livedata';+import {+ effect,+ fromPromise,+ LiveData,+ onComplete,+ onStart,+} from '../../../livedata';import type { WorkspaceMetadata } from '../metadata';import type { WorkspaceFlavourProvider } from '../providers/flavour';import type { WorkspaceProfileCacheStore } from '../stores/profile-cache';@@ -54,11 +60,12 @@ export class WorkspaceProfile extends Entity<{ metadata: WorkspaceMetadata }> {revalidate = effect(switchMap(() => {- if (!this.provider) {+ const provider = this.provider;+ if (!provider) {return EMPTY;}- return from(- this.provider.getWorkspaceProfile(this.props.metadata.id)+ return fromPromise(signal =>+ provider.getWorkspaceProfile(this.props.metadata.id, signal)).pipe(mergeMap(info => {if (info) {diff --git a/packages/common/infra/src/modules/workspace/providers/flavour.ts b/packages/common/infra/src/modules/workspace/providers/flavour.tsindex bdb3a4549e..76fe00500d 100644--- a/packages/common/infra/src/modules/workspace/providers/flavour.ts+++ b/packages/common/infra/src/modules/workspace/providers/flavour.ts@@ -47,7 +47,10 @@ export interface WorkspaceFlavourProvider {*/revalidate?: () => void;- getWorkspaceProfile(id: string): Promise<WorkspaceProfileInfo | undefined>;+ getWorkspaceProfile(+ id: string,+ signal?: AbortSignal+ ): Promise<WorkspaceProfileInfo | undefined>;getWorkspaceBlob(id: string, blob: string): Promise<Blob | null>;diff --git a/packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts b/packages/frontend/core/src/modules/workspace-engine/impls/cloud.tsindex 4fc4080237..e586c84cc4 100644--- a/packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts+++ b/packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts@@ -26,7 +26,7 @@ import {} from '@toeverything/infra';import { effect, globalBlockSuiteSchema, Service } from '@toeverything/infra';import { nanoid } from 'nanoid';-import { EMPTY, lastValueFrom, map, mergeMap, timeout } from 'rxjs';+import { EMPTY, map, mergeMap } from 'rxjs';import { applyUpdate, encodeStateAsUpdate } from 'yjs';import type {@@ -179,7 +179,8 @@ export class CloudWorkspaceFlavourProviderServiceisLoading$ = new LiveData(false);workspaces$ = new LiveData<WorkspaceMetadata[]>([]);async getWorkspaceProfile(- id: string+ id: string,+ signal?: AbortSignal): Promise<WorkspaceProfileInfo | undefined> {// get information from both cloud and local storage@@ -190,7 +191,7 @@ export class CloudWorkspaceFlavourProviderServiceconst localData = await docStorage.doc.get(id);const cloudData = await cloudStorage.pull(id);- const isOwner = await this.getIsOwner(id);+ const isOwner = await this.getIsOwner(id, signal);if (!cloudData && !localData) {return {@@ -255,18 +256,15 @@ export class CloudWorkspaceFlavourProviderService};}- private async getIsOwner(workspaceId: string) {+ private async getIsOwner(workspaceId: string, signal?: AbortSignal) {return (- await lastValueFrom(- this.graphqlService- .rxGql({- query: getIsOwnerQuery,- variables: {- workspaceId,- },- })- .pipe(timeout(3000))- )+ await this.graphqlService.gql({+ query: getIsOwnerQuery,+ variables: {+ workspaceId,+ },+ context: { signal },+ })).isOwner;}