Slightly optimize the facets request

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-05-03 13:17:03 +02:00
parent 42d2d8c02d
commit 12a345317a
3 changed files with 18 additions and 3 deletions
+5
View File
@@ -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) {