mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
fix(server): searchRandom response (#15580)
* fix searchRandom * add e2e * set outer limit
This commit is contained in:
parent
065d885ca0
commit
ba105d9f19
5 changed files with 60 additions and 9 deletions
|
|
@ -60,6 +60,8 @@ union all
|
|||
limit
|
||||
$14
|
||||
)
|
||||
limit
|
||||
$15
|
||||
|
||||
-- SearchRepository.searchSmart
|
||||
select
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue