1
0
mirror of https://github.com/immich-app/immich.git synced 2025-08-09 23:17:29 +02:00

fix(server): searchRandom response (#15580)

* fix searchRandom

* add e2e

* set outer limit
This commit is contained in:
Mert
2025-01-24 00:41:54 -05:00
committed by GitHub
parent 065d885ca0
commit ba105d9f19
5 changed files with 60 additions and 9 deletions

View File

@@ -60,6 +60,8 @@ union all
limit
$14
)
limit
$15
-- SearchRepository.searchSmart
select

View File

@@ -69,12 +69,13 @@ export class SearchRepository implements ISearchRepository {
},
],
})
searchRandom(size: number, options: AssetSearchOptions): Promise<AssetEntity[]> {
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);
return sql`${lessThan} union all ${greaterThan}`.execute(this.db) as any as Promise<AssetEntity[]>;
const { rows } = await sql`${lessThan} union all ${greaterThan} limit ${size}`.execute(this.db);
return rows as any as AssetEntity[];
}
@GenerateSql({