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:
Jan
2024-05-08 05:14:04 +02:00
committed by GitHub
parent 725d594027
commit 535c7a8618
2 changed files with 112 additions and 8 deletions

View File

@@ -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 }] })