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

This commit is contained in:
EYHN
2025-04-01 11:31:58 +00:00
parent cb7b5caa74
commit 521eb09a7a
3 changed files with 20 additions and 6 deletions

View File

@@ -452,10 +452,13 @@ export async function crawlingDocData({
rootYDoc: YDoc; rootYDoc: YDoc;
spaceId: string; spaceId: string;
docId: string; docId: string;
}): Promise<{ }): Promise<
| {
blocks: IndexerDocument<'block'>[]; blocks: IndexerDocument<'block'>[];
preview?: string; preview?: string;
}> { }
| undefined
> {
let docTitle = ''; let docTitle = '';
let summaryLenNeeded = 1000; let summaryLenNeeded = 1000;
let summary = ''; let summary = '';
@@ -482,7 +485,7 @@ export async function crawlingDocData({
} }
if (blocks.size === 0) { if (blocks.size === 0) {
return { blocks: [] }; return undefined;
} }
// find the nearest block that satisfies the predicate // find the nearest block that satisfies the predicate
@@ -514,7 +517,7 @@ export async function crawlingDocData({
} }
if (!rootBlockId) { if (!rootBlockId) {
return { blocks: [] }; return undefined;
} }
const queue: { parent?: string; id: string }[] = [{ id: rootBlockId }]; const queue: { parent?: string; id: string }[] = [{ id: rootBlockId }];

View File

@@ -381,6 +381,10 @@ export class IndexerSyncImpl implements IndexerSync {
spaceId: this.status.rootDocId, spaceId: this.status.rootDocId,
docId, docId,
}); });
if (!result) {
// doc is empty without root block, just skip
continue;
}
blocks = result.blocks; blocks = result.blocks;
preview = result.preview; preview = result.preview;
} catch (error) { } catch (error) {

View File

@@ -1,4 +1,5 @@
import { DocsSearchService } from '@affine/core/modules/docs-search'; import { DocsSearchService } from '@affine/core/modules/docs-search';
import { WorkspaceService } from '@affine/core/modules/workspace';
import { LiveData, useLiveData, useService } from '@toeverything/infra'; import { LiveData, useLiveData, useService } from '@toeverything/infra';
import { type ReactNode, useEffect, useMemo } from 'react'; import { type ReactNode, useEffect, useMemo } from 'react';
@@ -14,6 +15,7 @@ const PagePreviewInner = ({
fallback, fallback,
}: PagePreviewProps) => { }: PagePreviewProps) => {
const docSummary = useService(DocsSearchService); const docSummary = useService(DocsSearchService);
const workspaceService = useService(WorkspaceService);
const summary = useLiveData( const summary = useLiveData(
useMemo( useMemo(
() => LiveData.from(docSummary.watchDocSummary(pageId), null), () => LiveData.from(docSummary.watchDocSummary(pageId), null),
@@ -26,6 +28,11 @@ const PagePreviewInner = ({
return undo; return undo;
}, [docSummary, pageId]); }, [docSummary, pageId]);
useEffect(() => {
const undo = workspaceService.workspace.engine.doc.addPriority(pageId, 10);
return undo;
}, [workspaceService, pageId]);
const res = const res =
summary === null ? fallback : summary === '' ? emptyFallback : summary; summary === null ? fallback : summary === '' ? emptyFallback : summary;
return res; return res;