fix(db): collapse presentation-key groups without min(uuid)
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful

PostgreSQL has no min(uuid) aggregate, so every query that picked a group
representative with MIN over the item id failed with 42883: library browse,
search, Recently Added, the by-name endpoints and Upcoming.

- Pick the representative with an anti-join on (primary version, id)
- Cover the collapse with a repository test against a real PostgreSQL
This commit is contained in:
2026-09-13 13:18:11 +10:00
parent 25269263ce
commit 6e405af1dc
3 changed files with 236 additions and 7 deletions
@@ -219,9 +219,11 @@ public sealed partial class BaseItemRepository
}
else
{
// The representative is the row no other row in its group sorts before, not MIN(Id):
// PostgreSQL has no min(uuid) aggregate, while comparing two uuids is supported everywhere.
representativeIds = masterQuery
.GroupBy(e => e.PresentationUniqueKey)
.Select(g => g.Min(e => e.Id))
.Where(e => !masterQuery.Any(o => o.PresentationUniqueKey == e.PresentationUniqueKey && o.Id.CompareTo(e.Id) < 0))
.Select(e => e.Id)
.ToList();
}