fix(server): Offset of random endpoint could be higher than user's asset count (#4342)

* fix offset of all assets with correct ownerId

* (e2e): test if user does not have all assets
This commit is contained in:
Daniel Dietzler authored and GitHub committed 2023-10-04 12:51:44 -05:00
1 parent e571880c16
commit ff331ffad9
2 files changed
+33 -3

No files matched your search

@@ -435,7 +435,7 @@ export class AssetRepository implements IAssetRepository {
`SELECT *
FROM assets
WHERE "ownerId" = $1
OFFSET FLOOR(RANDOM() * (SELECT GREATEST(COUNT(*) - $2, 0) FROM ASSETS)) LIMIT $2`,
OFFSET FLOOR(RANDOM() * (SELECT GREATEST(COUNT(*) - $2, 0) FROM ASSETS WHERE "ownerId" = $1)) LIMIT $2`,
[ownerId, count],
);
}