mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-23 20:18:42 +08: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',
|
field: 'refDocId',
|
||||||
match: docId,
|
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',
|
'docId',
|
||||||
@@ -282,6 +270,11 @@ export class DocsSearchService extends Service {
|
|||||||
this.docsService.list.doc$(bucket.key).value?.title$.value ??
|
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 => {
|
return bucket.hits.nodes.map(node => {
|
||||||
const blockId = node.fields.blockId ?? '';
|
const blockId = node.fields.blockId ?? '';
|
||||||
const markdownPreview = node.fields.markdownPreview ?? '';
|
const markdownPreview = node.fields.markdownPreview ?? '';
|
||||||
@@ -359,18 +352,6 @@ export class DocsSearchService extends Service {
|
|||||||
field: 'parentFlavour',
|
field: 'parentFlavour',
|
||||||
match: 'affine:database',
|
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(
|
.pipe(
|
||||||
map(({ nodes }) => {
|
map(({ nodes }) => {
|
||||||
return nodes.map(node => {
|
return nodes
|
||||||
const additional =
|
.map(node => {
|
||||||
typeof node.fields.additional === 'string'
|
if (node.fields.docId === docId) {
|
||||||
? node.fields.additional
|
// Ignore if it is a link to the current document.
|
||||||
: node.fields.additional[0];
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
const additional =
|
||||||
docId:
|
typeof node.fields.additional === 'string'
|
||||||
typeof node.fields.docId === 'string'
|
? node.fields.additional
|
||||||
? node.fields.docId
|
: node.fields.additional[0];
|
||||||
: node.fields.docId[0],
|
|
||||||
rowId:
|
return {
|
||||||
typeof node.fields.blockId === 'string'
|
docId:
|
||||||
? node.fields.blockId
|
typeof node.fields.docId === 'string'
|
||||||
: node.fields.blockId[0],
|
? node.fields.docId
|
||||||
databaseBlockId:
|
: node.fields.docId[0],
|
||||||
typeof node.fields.parentBlockId === 'string'
|
rowId:
|
||||||
? node.fields.parentBlockId
|
typeof node.fields.blockId === 'string'
|
||||||
: node.fields.parentBlockId[0],
|
? node.fields.blockId
|
||||||
databaseName: DatabaseAdditionalSchema.safeParse(additional).data
|
: node.fields.blockId[0],
|
||||||
?.databaseName as string | undefined,
|
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) {
|
submit(result: QuickSearchItem | null) {
|
||||||
if (this.state$.value?.callback) {
|
if (this.state$.value?.callback) {
|
||||||
|
this.state$.value.sessions.forEach(session => session.dispose?.());
|
||||||
this.state$.value.callback(result);
|
this.state$.value.callback(result);
|
||||||
}
|
}
|
||||||
this.state$.next(null);
|
this.state$.next(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user