mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-16 13:21:57 +00:00
improve mentions speed (#5121)
Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
parent
f99998f529
commit
f5fcd03e27
@ -61,6 +61,25 @@ function packSearchResultsForListView (sections: SearchSection[]): SearchItem[]
|
|||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function searchCategory (
|
||||||
|
client: TxOperations,
|
||||||
|
cl: Ref<Class<Doc>>,
|
||||||
|
query: string,
|
||||||
|
categories: ObjectSearchCategory[]
|
||||||
|
): Promise<SearchSection | undefined> {
|
||||||
|
const r = await client.searchFulltext(
|
||||||
|
{
|
||||||
|
query: `${query}*`,
|
||||||
|
classes: [cl]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
limit: 5
|
||||||
|
}
|
||||||
|
)
|
||||||
|
const category = findCategoryByClass(categories, cl)
|
||||||
|
return category !== undefined ? { category, items: r.docs } : undefined
|
||||||
|
}
|
||||||
|
|
||||||
async function doFulltextSearch (
|
async function doFulltextSearch (
|
||||||
client: TxOperations,
|
client: TxOperations,
|
||||||
classes: Array<Ref<Class<Doc>>>,
|
classes: Array<Ref<Class<Doc>>>,
|
||||||
@ -68,18 +87,14 @@ async function doFulltextSearch (
|
|||||||
categories: ObjectSearchCategory[]
|
categories: ObjectSearchCategory[]
|
||||||
): Promise<SearchSection[]> {
|
): Promise<SearchSection[]> {
|
||||||
const sections: SearchSection[] = []
|
const sections: SearchSection[] = []
|
||||||
|
const promises: Array<Promise<SearchSection | undefined>> = []
|
||||||
for (const cl of classes) {
|
for (const cl of classes) {
|
||||||
const r = await client.searchFulltext(
|
promises.push(searchCategory(client, cl, query, categories))
|
||||||
{
|
}
|
||||||
query: `${query}*`,
|
|
||||||
classes: [cl]
|
const resolvedSections = await Promise.all(promises)
|
||||||
},
|
for (const s of resolvedSections) {
|
||||||
{
|
if (s !== undefined) sections.push(s)
|
||||||
limit: 5
|
|
||||||
}
|
|
||||||
)
|
|
||||||
const category = findCategoryByClass(categories, cl)
|
|
||||||
if (category !== undefined) sections.push({ category, items: r.docs })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sections.sort((a, b) => {
|
return sections.sort((a, b) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user