mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 01:12:58 -04:00
maybe fix sql generation
This commit is contained in:
parent
e851884f88
commit
34f72a8251
@ -116,7 +116,7 @@ export const DummyValue = {
|
||||
DATE: new Date(),
|
||||
TIME_BUCKET: '2024-01-01T00:00:00.000Z',
|
||||
BOOLEAN: true,
|
||||
VECTOR: '[1,2,3]',
|
||||
VECTOR: JSON.stringify(Array.from({ length: 512 }, () => 0)),
|
||||
};
|
||||
|
||||
export const GENERATE_SQL_KEY = 'generate-sql-key';
|
||||
|
@ -65,6 +65,8 @@ limit
|
||||
|
||||
-- SearchRepository.searchSmart
|
||||
begin
|
||||
set
|
||||
local vchordrq.probes = 1
|
||||
select
|
||||
"assets".*
|
||||
from
|
||||
@ -84,10 +86,12 @@ limit
|
||||
$7
|
||||
offset
|
||||
$8
|
||||
rollback
|
||||
commit
|
||||
|
||||
-- SearchRepository.searchDuplicates
|
||||
begin
|
||||
set
|
||||
local vchordrq.probes = 1
|
||||
with
|
||||
"cte" as (
|
||||
select
|
||||
@ -115,10 +119,12 @@ from
|
||||
"cte"
|
||||
where
|
||||
"cte"."distance" <= $7
|
||||
rollback
|
||||
commit
|
||||
|
||||
-- SearchRepository.searchFaces
|
||||
begin
|
||||
set
|
||||
local vchordrq.probes = 1
|
||||
with
|
||||
"cte" as (
|
||||
select
|
||||
@ -144,7 +150,7 @@ from
|
||||
"cte"
|
||||
where
|
||||
"cte"."distance" <= $4
|
||||
rollback
|
||||
commit
|
||||
|
||||
-- SearchRepository.searchPlaces
|
||||
select
|
||||
|
@ -5,8 +5,8 @@ import { randomUUID } from 'node:crypto';
|
||||
import { DB, Exif } from 'src/db';
|
||||
import { DummyValue, GenerateSql } from 'src/decorators';
|
||||
import { MapAsset } from 'src/dtos/asset-response.dto';
|
||||
import { AssetStatus, AssetType, AssetVisibility, DatabaseExtension, VectorIndex } from 'src/enum';
|
||||
import { cachedVectorExtension, probes } from 'src/repositories/database.repository';
|
||||
import { AssetStatus, AssetType, AssetVisibility, VectorIndex } from 'src/enum';
|
||||
import { probes } from 'src/repositories/database.repository';
|
||||
import { anyUuid, asUuid, searchAssetBuilder } from 'src/utils/database';
|
||||
import { paginationHelper } from 'src/utils/pagination';
|
||||
import { isValidInteger } from 'src/validation';
|
||||
@ -239,9 +239,7 @@ export class SearchRepository {
|
||||
}
|
||||
|
||||
return this.db.transaction().execute(async (trx) => {
|
||||
if (cachedVectorExtension === DatabaseExtension.VECTORCHORD) {
|
||||
await sql`set local vchord.probes = ${sql.lit(probes[VectorIndex.CLIP])}`.execute(trx);
|
||||
}
|
||||
await sql`set local vchordrq.probes = ${sql.lit(probes[VectorIndex.CLIP])}`.execute(trx);
|
||||
const items = await searchAssetBuilder(trx, options)
|
||||
.innerJoin('smart_search', 'assets.id', 'smart_search.assetId')
|
||||
.orderBy(sql`smart_search.embedding <=> ${options.embedding}`)
|
||||
@ -265,10 +263,7 @@ export class SearchRepository {
|
||||
})
|
||||
searchDuplicates({ assetId, embedding, maxDistance, type, userIds }: AssetDuplicateSearch) {
|
||||
return this.db.transaction().execute(async (trx) => {
|
||||
if (cachedVectorExtension === DatabaseExtension.VECTORCHORD) {
|
||||
await sql`set local vchord.probes = ${sql.lit(probes[VectorIndex.CLIP])}`.execute(trx);
|
||||
}
|
||||
|
||||
await sql`set local vchordrq.probes = ${sql.lit(probes[VectorIndex.CLIP])}`.execute(trx);
|
||||
return await trx
|
||||
.with('cte', (qb) =>
|
||||
qb
|
||||
@ -311,10 +306,7 @@ export class SearchRepository {
|
||||
}
|
||||
|
||||
return this.db.transaction().execute(async (trx) => {
|
||||
if (cachedVectorExtension === DatabaseExtension.VECTORCHORD) {
|
||||
await sql`set local vchord.probes = ${sql.lit(probes[VectorIndex.FACE])}`.execute(trx);
|
||||
}
|
||||
|
||||
await sql`set local vchordrq.probes = ${sql.lit(probes[VectorIndex.FACE])}`.execute(trx);
|
||||
return await trx
|
||||
.with('cte', (qb) =>
|
||||
qb
|
||||
|
Loading…
x
Reference in New Issue
Block a user