mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 01:12:58 -04:00
fix(server): /search/random API returns same assets every call (#15682)
* Fix for server searchRandom function not returning random results * Fix lint
This commit is contained in:
parent
f780a56e24
commit
206412267a
@ -36,7 +36,7 @@ offset
|
||||
and "assets"."deletedAt" is null
|
||||
and "assets"."id" < $6
|
||||
order by
|
||||
"assets"."id"
|
||||
random()
|
||||
limit
|
||||
$7
|
||||
)
|
||||
@ -56,7 +56,7 @@ union all
|
||||
and "assets"."deletedAt" is null
|
||||
and "assets"."id" > $13
|
||||
order by
|
||||
"assets"."id"
|
||||
random()
|
||||
limit
|
||||
$14
|
||||
)
|
||||
|
@ -72,8 +72,14 @@ export class SearchRepository implements ISearchRepository {
|
||||
async searchRandom(size: number, options: AssetSearchOptions): Promise<AssetEntity[]> {
|
||||
const uuid = randomUUID();
|
||||
const builder = searchAssetBuilder(this.db, options);
|
||||
const lessThan = builder.where('assets.id', '<', uuid).orderBy('assets.id').limit(size);
|
||||
const greaterThan = builder.where('assets.id', '>', uuid).orderBy('assets.id').limit(size);
|
||||
const lessThan = builder
|
||||
.where('assets.id', '<', uuid)
|
||||
.orderBy(sql`random()`)
|
||||
.limit(size);
|
||||
const greaterThan = builder
|
||||
.where('assets.id', '>', uuid)
|
||||
.orderBy(sql`random()`)
|
||||
.limit(size);
|
||||
const { rows } = await sql`${lessThan} union all ${greaterThan} limit ${size}`.execute(this.db);
|
||||
return rows as any as AssetEntity[];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user