From 2c4b4912c2ed6ab5466176d1409df09ea6fceee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Wed, 20 May 2026 16:59:39 +0200 Subject: [PATCH] Add whereNotNull to count query sort-field EXISTS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The list CTE's INNER JOIN on search already excludes entities whose sort-field value is NULL (truncated long values stored as NULL by buildEntitySearch). Add the same whereNotNull to the count query's EXISTS so totalItems matches the reachable set. Matters for fields like metadata.description where ~128K entities have NULL values. Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Fredrik Adelöw --- plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts b/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts index e194d492f0..2a3c7aad9d 100644 --- a/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts +++ b/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts @@ -505,7 +505,8 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog { this.database('search') .select(this.database.raw(1)) .whereRaw('search.entity_id = final_entities.entity_id') - .where('search.key', sortField.field), + .where('search.key', sortField.field) + .whereNotNull('search.value'), ); }