mirror of
https://github.com/immich-app/immich.git
synced 2026-03-04 09:57:33 +03:00
refactor(server): db env (#13167)
This commit is contained in:
@@ -3,7 +3,7 @@ import { InjectDataSource } from '@nestjs/typeorm';
|
||||
import AsyncLock from 'async-lock';
|
||||
import semver from 'semver';
|
||||
import { POSTGRES_VERSION_RANGE, VECTOR_VERSION_RANGE, VECTORS_VERSION_RANGE } from 'src/constants';
|
||||
import { getVectorExtension } from 'src/database.config';
|
||||
import { IConfigRepository } from 'src/interfaces/config.interface';
|
||||
import {
|
||||
DatabaseExtension,
|
||||
DatabaseLock,
|
||||
@@ -22,12 +22,15 @@ import { DataSource, EntityManager, QueryRunner } from 'typeorm';
|
||||
@Instrumentation()
|
||||
@Injectable()
|
||||
export class DatabaseRepository implements IDatabaseRepository {
|
||||
private vectorExtension: VectorExtension;
|
||||
readonly asyncLock = new AsyncLock();
|
||||
|
||||
constructor(
|
||||
@InjectDataSource() private dataSource: DataSource,
|
||||
@Inject(ILoggerRepository) private logger: ILoggerRepository,
|
||||
@Inject(IConfigRepository) configRepository: IConfigRepository,
|
||||
) {
|
||||
this.vectorExtension = configRepository.getEnv().database.vectorExtension;
|
||||
this.logger.setContext(DatabaseRepository.name);
|
||||
}
|
||||
|
||||
@@ -119,7 +122,7 @@ export class DatabaseRepository implements IDatabaseRepository {
|
||||
try {
|
||||
await this.dataSource.query(`REINDEX INDEX ${index}`);
|
||||
} catch (error) {
|
||||
if (getVectorExtension() !== DatabaseExtension.VECTORS) {
|
||||
if (this.vectorExtension !== DatabaseExtension.VECTORS) {
|
||||
throw error;
|
||||
}
|
||||
this.logger.warn(`Could not reindex index ${index}. Attempting to auto-fix.`);
|
||||
@@ -141,7 +144,7 @@ export class DatabaseRepository implements IDatabaseRepository {
|
||||
}
|
||||
|
||||
async shouldReindex(name: VectorIndex): Promise<boolean> {
|
||||
if (getVectorExtension() !== DatabaseExtension.VECTORS) {
|
||||
if (this.vectorExtension !== DatabaseExtension.VECTORS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user