mirror of
https://github.com/immich-app/immich.git
synced 2026-03-07 02:27:23 +03:00
Random Endpoint use querybuilder and return exifInfo (#9301)
* Random Endpoint use querybuilder and return exifInfo * Add GenerateSql * Commit missing sql changes
This commit is contained in:
@@ -571,15 +571,14 @@ export class AssetRepository implements IAssetRepository {
|
||||
return result;
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID, DummyValue.NUMBER] })
|
||||
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(*) - $2, 0) FROM ASSETS WHERE "ownerId" = $1)) LIMIT $2`,
|
||||
[ownerId, count],
|
||||
);
|
||||
const builder = this.getBuilder({
|
||||
userIds: [ownerId],
|
||||
exifInfo: true,
|
||||
});
|
||||
|
||||
return builder.orderBy('RANDOM()').limit(count).getMany();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [{ size: TimeBucketSize.MONTH }] })
|
||||
|
||||
Reference in New Issue
Block a user