mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
feat(server): random assets API (#4184)
* feat(server): get random assets API * Fix tests * Use correct validation annotation * Fix offset use in query * Update API specs * Fix typo * Random assets e2e tests * Improve e2e tests
This commit is contained in:
@@ -429,6 +429,17 @@ export class AssetRepository implements IAssetRepository {
|
||||
return result;
|
||||
}
|
||||
|
||||
getRandom(ownerId: string, count: number): Promise<AssetEntity[]> {
|
||||
// can't use queryBuilder because of custom OFFSET clause
|
||||
return this.repository.query(
|
||||
`SELECT *
|
||||
FROM assets
|
||||
WHERE "ownerId" = $1
|
||||
OFFSET FLOOR(RANDOM() * (SELECT GREATEST(COUNT(*) - 1, 0) FROM ASSETS)) LIMIT $2`,
|
||||
[ownerId, count],
|
||||
);
|
||||
}
|
||||
|
||||
getTimeBuckets(options: TimeBucketOptions): Promise<TimeBucketItem[]> {
|
||||
const truncateValue = truncateMap[options.size];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user