Skip to content

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.

fix(nbstore): adjust indexer logic (#11355)

EYHN521eb09a7a42
diff --git a/packages/common/nbstore/src/sync/indexer/crawler.ts b/packages/common/nbstore/src/sync/indexer/crawler.ts
index 769dd99e62..348c3613f5 100644
--- a/packages/common/nbstore/src/sync/indexer/crawler.ts
+++ b/packages/common/nbstore/src/sync/indexer/crawler.ts
@@ -452,10 +452,13 @@ export async function crawlingDocData({
rootYDoc: YDoc;
spaceId: string;
docId: string;
-}): Promise<{
- blocks: IndexerDocument<'block'>[];
- preview?: string;
-}> {
+}): Promise<
+ | {
+ blocks: IndexerDocument<'block'>[];
+ preview?: string;
+ }
+ | undefined
+> {
let docTitle = '';
let summaryLenNeeded = 1000;
let summary = '';
@@ -482,7 +485,7 @@ export async function crawlingDocData({
}
if (blocks.size === 0) {
- return { blocks: [] };
+ return undefined;
}
// find the nearest block that satisfies the predicate
@@ -514,7 +517,7 @@ export async function crawlingDocData({
}
if (!rootBlockId) {
- return { blocks: [] };
+ return undefined;
}
const queue: { parent?: string; id: string }[] = [{ id: rootBlockId }];
diff --git a/packages/common/nbstore/src/sync/indexer/index.ts b/packages/common/nbstore/src/sync/indexer/index.ts
index 55d6a50b74..9dfe446c8a 100644
--- a/packages/common/nbstore/src/sync/indexer/index.ts
+++ b/packages/common/nbstore/src/sync/indexer/index.ts
@@ -381,6 +381,10 @@ export class IndexerSyncImpl implements IndexerSync {
spaceId: this.status.rootDocId,
docId,
});
+ if (!result) {
+ // doc is empty without root block, just skip
+ continue;
+ }
blocks = result.blocks;
preview = result.preview;
} catch (error) {
diff --git a/packages/frontend/core/src/components/page-list/page-content-preview.tsx b/packages/frontend/core/src/components/page-list/page-content-preview.tsx
index 017fc49244..6f761841ca 100644
--- a/packages/frontend/core/src/components/page-list/page-content-preview.tsx
+++ b/packages/frontend/core/src/components/page-list/page-content-preview.tsx
@@ -1,4 +1,5 @@
import { DocsSearchService } from '@affine/core/modules/docs-search';
+import { WorkspaceService } from '@affine/core/modules/workspace';
import { LiveData, useLiveData, useService } from '@toeverything/infra';
import { type ReactNode, useEffect, useMemo } from 'react';
@@ -14,6 +15,7 @@ const PagePreviewInner = ({
fallback,
}: PagePreviewProps) => {
const docSummary = useService(DocsSearchService);
+ const workspaceService = useService(WorkspaceService);
const summary = useLiveData(
useMemo(
() => LiveData.from(docSummary.watchDocSummary(pageId), null),
@@ -26,6 +28,11 @@ const PagePreviewInner = ({
return undo;
}, [docSummary, pageId]);
+ useEffect(() => {
+ const undo = workspaceService.workspace.engine.doc.addPriority(pageId, 10);
+ return undo;
+ }, [workspaceService, pageId]);
+
const res =
summary === null ? fallback : summary === '' ? emptyFallback : summary;
return res;