mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 23:56:36 +08:00
fix(core): subscribe search not unsubscribe (#11929)
This commit is contained in:
@@ -249,6 +249,7 @@ export class LinkedDocPopover extends SignalWatcher(
|
||||
override disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
this._menusItemsEffectCleanup();
|
||||
this._updateLinkedDocGroupAbortController?.abort();
|
||||
}
|
||||
|
||||
override render() {
|
||||
|
||||
@@ -225,17 +225,26 @@ export class FullTextInvertedIndex implements InvertedIndex {
|
||||
)?.value ?? 0;
|
||||
for (const token of queryTokens) {
|
||||
const key = InvertedIndexKey.forString(this.fieldKey, token.term);
|
||||
const objs = await trx
|
||||
.objectStore('invertedIndex')
|
||||
.index('key')
|
||||
.getAll(
|
||||
IDBKeyRange.bound(
|
||||
[this.table, key.buffer()],
|
||||
[this.table, key.add1().buffer()],
|
||||
false,
|
||||
true
|
||||
)
|
||||
);
|
||||
const objs = [
|
||||
// match exact
|
||||
await trx
|
||||
.objectStore('invertedIndex')
|
||||
.index('key')
|
||||
.get([this.table, key.buffer()]),
|
||||
// match prefix
|
||||
...(await trx
|
||||
.objectStore('invertedIndex')
|
||||
.index('key')
|
||||
.getAll(
|
||||
IDBKeyRange.bound(
|
||||
[this.table, key.buffer()],
|
||||
[this.table, key.add1().buffer()],
|
||||
true,
|
||||
true
|
||||
),
|
||||
5000 // get maximum 5000 items for prefix match
|
||||
)),
|
||||
];
|
||||
const submatched: {
|
||||
nid: number;
|
||||
score: number;
|
||||
@@ -245,6 +254,9 @@ export class FullTextInvertedIndex implements InvertedIndex {
|
||||
};
|
||||
}[] = [];
|
||||
for (const obj of objs) {
|
||||
if (!obj) {
|
||||
continue;
|
||||
}
|
||||
const key = InvertedIndexKey.fromBuffer(obj.key);
|
||||
const originTokenTerm = key.asString();
|
||||
const matchLength = token.term.length;
|
||||
|
||||
@@ -260,6 +260,8 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
@query('.search-input')
|
||||
accessor searchInput!: HTMLInputElement;
|
||||
|
||||
private _menuGroupAbortController = new AbortController();
|
||||
|
||||
override connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._updateSearchGroup();
|
||||
@@ -273,6 +275,7 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
override disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
document.removeEventListener('keydown', this._handleKeyDown);
|
||||
this._menuGroupAbortController.abort();
|
||||
}
|
||||
|
||||
override render() {
|
||||
@@ -385,13 +388,15 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
}
|
||||
|
||||
private _updateSearchGroup() {
|
||||
this._menuGroupAbortController.abort();
|
||||
this._menuGroupAbortController = new AbortController();
|
||||
switch (this._mode) {
|
||||
case AddPopoverMode.Tags: {
|
||||
this._searchGroups = [
|
||||
this.searchMenuConfig.getTagMenuGroup(
|
||||
this._query,
|
||||
this._addTagChip,
|
||||
this.abortController.signal
|
||||
this._menuGroupAbortController.signal
|
||||
),
|
||||
];
|
||||
break;
|
||||
@@ -401,7 +406,7 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
this.searchMenuConfig.getCollectionMenuGroup(
|
||||
this._query,
|
||||
this._addCollectionChip,
|
||||
this.abortController.signal
|
||||
this._menuGroupAbortController.signal
|
||||
),
|
||||
];
|
||||
break;
|
||||
@@ -410,7 +415,7 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
const docGroup = this.searchMenuConfig.getDocMenuGroup(
|
||||
this._query,
|
||||
this._addDocChip,
|
||||
this.abortController.signal
|
||||
this._menuGroupAbortController.signal
|
||||
);
|
||||
if (!this._query) {
|
||||
this._searchGroups = [docGroup];
|
||||
@@ -418,12 +423,12 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
const tagGroup = this.searchMenuConfig.getTagMenuGroup(
|
||||
this._query,
|
||||
this._addTagChip,
|
||||
this.abortController.signal
|
||||
this._menuGroupAbortController.signal
|
||||
);
|
||||
const collectionGroup = this.searchMenuConfig.getCollectionMenuGroup(
|
||||
this._query,
|
||||
this._addCollectionChip,
|
||||
this.abortController.signal
|
||||
this._menuGroupAbortController.signal
|
||||
);
|
||||
const nothing = html``;
|
||||
this._searchGroups = [
|
||||
|
||||
@@ -37,12 +37,12 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
|
||||
searchResult = await new Promise((resolve, reject) =>
|
||||
framework.get(QuickSearchService).quickSearch.show(
|
||||
[
|
||||
framework.get(RecentDocsQuickSearchSession),
|
||||
framework.get(CreationQuickSearchSession),
|
||||
framework.get(DocsQuickSearchSession),
|
||||
framework.get(LinksQuickSearchSession),
|
||||
framework.get(ExternalLinksQuickSearchSession),
|
||||
framework.get(JournalsQuickSearchSession),
|
||||
framework.createEntity(RecentDocsQuickSearchSession),
|
||||
framework.createEntity(CreationQuickSearchSession),
|
||||
framework.createEntity(DocsQuickSearchSession),
|
||||
framework.createEntity(LinksQuickSearchSession),
|
||||
framework.createEntity(ExternalLinksQuickSearchSession),
|
||||
framework.createEntity(JournalsQuickSearchSession),
|
||||
],
|
||||
result => {
|
||||
if (result === null) {
|
||||
|
||||
@@ -116,4 +116,8 @@ export class DocsQuickSearchSession
|
||||
setQuery(query: string) {
|
||||
this.query$.next(query);
|
||||
}
|
||||
|
||||
override dispose(): void {
|
||||
this.query.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user