fix(nbstore): fix search slow (#12800)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved search results by ensuring links to the current document are
properly excluded from related document and database searches.
- Enhanced session management in quick search by ensuring all active
sessions are cleaned up before processing new search results.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
EYHN
2025-06-12 16:43:55 +09:00
committed by GitHub
parent b4401a8abf
commit 7284320355
2 changed files with 35 additions and 46 deletions

View File

@@ -240,18 +240,6 @@ export class DocsSearchService extends Service {
field: 'refDocId',
match: docId,
},
// Ignore if it is a link to the current document.
{
type: 'boolean',
occur: 'must_not',
queries: [
{
type: 'match',
field: 'docId',
match: docId,
},
],
},
],
},
'docId',
@@ -282,6 +270,11 @@ export class DocsSearchService extends Service {
this.docsService.list.doc$(bucket.key).value?.title$.value ??
'';
if (bucket.key === docId) {
// Ignore if it is a link to the current document.
return [];
}
return bucket.hits.nodes.map(node => {
const blockId = node.fields.blockId ?? '';
const markdownPreview = node.fields.markdownPreview ?? '';
@@ -359,18 +352,6 @@ export class DocsSearchService extends Service {
field: 'parentFlavour',
match: 'affine:database',
},
// Ignore if it is a link to the current document.
{
type: 'boolean',
occur: 'must_not',
queries: [
{
type: 'match',
field: 'docId',
match: docId,
},
],
},
],
},
{
@@ -382,29 +363,36 @@ export class DocsSearchService extends Service {
)
.pipe(
map(({ nodes }) => {
return nodes.map(node => {
const additional =
typeof node.fields.additional === 'string'
? node.fields.additional
: node.fields.additional[0];
return nodes
.map(node => {
if (node.fields.docId === docId) {
// Ignore if it is a link to the current document.
return null;
}
return {
docId:
typeof node.fields.docId === 'string'
? node.fields.docId
: node.fields.docId[0],
rowId:
typeof node.fields.blockId === 'string'
? node.fields.blockId
: node.fields.blockId[0],
databaseBlockId:
typeof node.fields.parentBlockId === 'string'
? node.fields.parentBlockId
: node.fields.parentBlockId[0],
databaseName: DatabaseAdditionalSchema.safeParse(additional).data
?.databaseName as string | undefined,
};
});
const additional =
typeof node.fields.additional === 'string'
? node.fields.additional
: node.fields.additional[0];
return {
docId:
typeof node.fields.docId === 'string'
? node.fields.docId
: node.fields.docId[0],
rowId:
typeof node.fields.blockId === 'string'
? node.fields.blockId
: node.fields.blockId[0],
databaseBlockId:
typeof node.fields.parentBlockId === 'string'
? node.fields.parentBlockId
: node.fields.parentBlockId[0],
databaseName: DatabaseAdditionalSchema.safeParse(additional)
.data?.databaseName as string | undefined,
};
})
.filter((item): item is NonNullable<typeof item> => item !== null);
})
);
}

View File

@@ -106,6 +106,7 @@ export class QuickSearch extends Entity {
submit(result: QuickSearchItem | null) {
if (this.state$.value?.callback) {
this.state$.value.sessions.forEach(session => session.dispose?.());
this.state$.value.callback(result);
}
this.state$.next(null);