Slightly optimize the facets request
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Remove unnecessary join in the entity facets endpoint, exclude nulls
|
||||
@@ -1729,6 +1729,17 @@ describe('DefaultEntitiesCatalog', () => {
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
catalog.facets({
|
||||
facets: ['kind'],
|
||||
filter: { not: { key: 'metadata.name', values: ['two'] } },
|
||||
}),
|
||||
).resolves.toEqual({
|
||||
facets: {
|
||||
kind: [{ value: 'k', count: 1 }],
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -678,10 +678,9 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog {
|
||||
|
||||
for (const facet of request.facets) {
|
||||
const dbQuery = db<DbSearchRow>('search')
|
||||
.join('final_entities', 'search.entity_id', 'final_entities.entity_id')
|
||||
.where('search.key', facet.toLocaleLowerCase('en-US'))
|
||||
.count('search.entity_id as count')
|
||||
.select({ value: 'search.original_value' })
|
||||
.whereNotNull('search.original_value')
|
||||
.select({ value: 'search.original_value', count: db.raw('count(*)') })
|
||||
.groupBy('search.original_value');
|
||||
|
||||
if (request?.filter) {
|
||||
|
||||
Reference in New Issue
Block a user