UBER-881: Fix labels list view numbers (#3721)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-09-20 23:22:28 +07:00 committed by GitHub
parent 25b048f8e8
commit 5c51f95c6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 51 deletions

View File

@ -75,7 +75,7 @@
} }
: { targetClass: _class } : { targetClass: _class }
objectsPromise = client.findAll(tags.class.TagElement, resultQuery) objectsPromise = client.findAll(tags.class.TagElement, resultQuery)
const _objects = await objectsPromise const _objects = sortFilterValues(await objectsPromise, isSelected)
if (qid !== queryId) { if (qid !== queryId) {
return return
} }
@ -87,7 +87,6 @@
categories.sort((a, b) => { categories.sort((a, b) => {
const alen = objects.filter((el) => el.category === a._id && isSelected(el)) const alen = objects.filter((el) => el.category === a._id && isSelected(el))
const blen = objects.filter((el) => el.category === b._id && isSelected(el)) const blen = objects.filter((el) => el.category === b._id && isSelected(el))
console.log(alen.length, blen.length, selected.length)
return blen.length - alen.length return blen.length - alen.length
}) })
categories = categories categories = categories
@ -182,10 +181,7 @@
<Loading /> <Loading />
{:else} {:else}
{#each categories as cat, i} {#each categories as cat, i}
{@const values = sortFilterValues( {@const values = objects.filter((el) => el.category === cat._id)}
objects.filter((el) => el.category === cat._id),
isSelected
)}
{#if values.length > 0} {#if values.length > 0}
{#if i > 0}<div class="menu-separator" />{/if} {#if i > 0}<div class="menu-separator" />{/if}
<div class="sticky-wrapper"> <div class="sticky-wrapper">

View File

@ -41,8 +41,6 @@
export let selection: number | undefined = undefined export let selection: number | undefined = undefined
export let compactMode: boolean = false export let compactMode: boolean = false
export let documents: Doc[] | undefined = undefined
const limiter = new RateLimitter(() => ({ rate: 10 })) const limiter = new RateLimitter(() => ({ rate: 10 }))
let docs: Doc[] = [] let docs: Doc[] = []
@ -65,54 +63,62 @@
$: queryNoLookup = noLookup(resultQuery) $: queryNoLookup = noLookup(resultQuery)
let fastQueryIds: Ref<Doc>[] = [] let fastQueryIds: Ref<Doc>[] = []
$: if (documents === undefined) {
docsQuery.query( let categoryQueryOptions: Partial<FindOptions<Doc>>
_class, $: categoryQueryOptions = {
queryNoLookup, ...resultOptions,
(res) => { projection: {
fastDocs = res ...resultOptions.projection,
fastQueryIds = res.map((it) => it._id) _id: 1,
}, _class: 1,
{ ...getProjection(viewOptions.groupBy, queryNoLookup)
...resultOptions, }
projection: {
...resultOptions.projection,
_id: 1,
_class: 1,
...getProjection(viewOptions.groupBy, queryNoLookup)
},
limit: 1000
}
)
} else {
docsQuery.unsubscribe()
} }
$: if (fastQueryIds.length > 0) { $: docsQuery.query(
docsQuerySlow.query( _class,
_class, queryNoLookup,
{ ...queryNoLookup, _id: { $nin: fastQueryIds } }, (res) => {
(res) => { fastDocs = res
slowDocs = res fastQueryIds = res.map((it) => it._id)
}, },
{ { ...categoryQueryOptions, limit: 1000 }
...resultOptions, )
projection: { $: {
...resultOptions.projection, let doQuery = false
_id: 1, let _idQuery: DocumentQuery<Doc>['_id'] = { $nin: fastQueryIds }
_class: 1,
...getProjection(viewOptions.groupBy, queryNoLookup) if (fastQueryIds.length > 0) {
doQuery = true
if (typeof resultQuery._id === 'object' && resultQuery._id?.$in !== undefined) {
const inIds = new Set(resultQuery._id.$in)
fastQueryIds.forEach((it) => inIds.delete(it))
_idQuery = { $in: Array.from(inIds) }
if (inIds.size === 0) {
doQuery = false
} }
} else if (typeof resultQuery._id === 'object' && resultQuery._id?.$nin !== undefined) {
const ninIds = new Set(resultQuery._id.$in)
fastQueryIds.forEach((it) => ninIds.add(it))
_idQuery = { $nin: Array.from(ninIds) }
} }
) }
} else {
docsQuerySlow.unsubscribe() if (doQuery) {
docsQuerySlow.query(
_class,
{ ...queryNoLookup, _id: _idQuery },
(res) => {
slowDocs = res
},
categoryQueryOptions
)
} else {
docsQuerySlow.unsubscribe()
}
} }
$: if (documents === undefined) { $: docs = [...fastDocs, ...slowDocs]
docs = [...fastDocs, ...slowDocs]
} else {
docs = documents
}
function getProjection (fields: string[], query: DocumentQuery<Doc>): Record<string, number> { function getProjection (fields: string[], query: DocumentQuery<Doc>): Record<string, number> {
const res: Record<string, number> = {} const res: Record<string, number> = {}