mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
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:
@@ -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);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user