changeset improvements

Signed-off-by: Tyler Davis <tylerd@canva.com>
This commit is contained in:
Tyler Davis
2025-03-25 11:36:45 +11:00
parent 7cc4995abf
commit b8b327dcdb
2 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -2,4 +2,4 @@
'@backstage/plugin-catalog-backend': patch
---
Fix for duplicate results in queryEntities when using an orderField
Fix for duplicate results in `queryEntities` when providing an `orderField` parameter
@@ -273,6 +273,24 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog {
const sortField = cursor.orderFields.at(0);
if (sortField) {
const duplicateCheck = await this.database('search')
.select('entity_id', 'key', 'value')
.count('* as count')
.where('key', '=', sortField.field)
.groupBy('entity_id', 'key', 'value')
.having(this.database.raw('count(*) > 1'))
.limit(5);
if (duplicateCheck.length > 0) {
this.logger.warn(
`Found duplicate search entries for field ${
sortField.field
}: ${JSON.stringify(duplicateCheck)}`,
);
}
}
// The first part of the query builder is a subquery that applies all of the
// filtering.
const dbQuery = this.database.with(