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