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