improve mentions speed (#5121)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
Vyacheslav Tumanov 2024-04-01 13:24:11 +05:00 committed by GitHub
parent f99998f529
commit f5fcd03e27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -61,14 +61,12 @@ function packSearchResultsForListView (sections: SearchSection[]): SearchItem[]
return results
}
async function doFulltextSearch (
async function searchCategory (
client: TxOperations,
classes: Array<Ref<Class<Doc>>>,
cl: Ref<Class<Doc>>,
query: string,
categories: ObjectSearchCategory[]
): Promise<SearchSection[]> {
const sections: SearchSection[] = []
for (const cl of classes) {
): Promise<SearchSection | undefined> {
const r = await client.searchFulltext(
{
query: `${query}*`,
@ -79,7 +77,24 @@ async function doFulltextSearch (
}
)
const category = findCategoryByClass(categories, cl)
if (category !== undefined) sections.push({ category, items: r.docs })
return category !== undefined ? { category, items: r.docs } : undefined
}
async function doFulltextSearch (
client: TxOperations,
classes: Array<Ref<Class<Doc>>>,
query: string,
categories: ObjectSearchCategory[]
): Promise<SearchSection[]> {
const sections: SearchSection[] = []
const promises: Array<Promise<SearchSection | undefined>> = []
for (const cl of classes) {
promises.push(searchCategory(client, cl, query, categories))
}
const resolvedSections = await Promise.all(promises)
for (const s of resolvedSections) {
if (s !== undefined) sections.push(s)
}
return sections.sort((a, b) => {