mirror of
https://github.com/immich-app/immich.git
synced 2025-06-01 20:54:22 -04:00
remove nesting
This commit is contained in:
parent
1691706666
commit
c15507baad
@ -32,18 +32,20 @@ export async function getVectorExtension(runner: Kysely<DB> | QueryRunner): Prom
|
|||||||
}
|
}
|
||||||
|
|
||||||
cachedVectorExtension = new ConfigRepository().getEnv().database.vectorExtension;
|
cachedVectorExtension = new ConfigRepository().getEnv().database.vectorExtension;
|
||||||
if (!cachedVectorExtension) {
|
if (cachedVectorExtension) {
|
||||||
let availableExtensions: { name: VectorExtension }[];
|
return cachedVectorExtension;
|
||||||
const query = `SELECT name FROM pg_available_extensions WHERE name IN (${VECTOR_EXTENSIONS.map((ext) => `'${ext}'`).join(', ')})`;
|
|
||||||
if (runner instanceof Kysely) {
|
|
||||||
const { rows } = await sql.raw<{ name: VectorExtension }>(query).execute(runner);
|
|
||||||
availableExtensions = rows;
|
|
||||||
} else {
|
|
||||||
availableExtensions = (await runner.query(query)) as { name: VectorExtension }[];
|
|
||||||
}
|
|
||||||
const extensionNames = new Set(availableExtensions.map((row) => row.name));
|
|
||||||
cachedVectorExtension = VECTOR_EXTENSIONS.find((ext) => extensionNames.has(ext));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let availableExtensions: { name: VectorExtension }[];
|
||||||
|
const query = `SELECT name FROM pg_available_extensions WHERE name IN (${VECTOR_EXTENSIONS.map((ext) => `'${ext}'`).join(', ')})`;
|
||||||
|
if (runner instanceof Kysely) {
|
||||||
|
const { rows } = await sql.raw<{ name: VectorExtension }>(query).execute(runner);
|
||||||
|
availableExtensions = rows;
|
||||||
|
} else {
|
||||||
|
availableExtensions = (await runner.query(query)) as { name: VectorExtension }[];
|
||||||
|
}
|
||||||
|
const extensionNames = new Set(availableExtensions.map((row) => row.name));
|
||||||
|
cachedVectorExtension = VECTOR_EXTENSIONS.find((ext) => extensionNames.has(ext));
|
||||||
if (!cachedVectorExtension) {
|
if (!cachedVectorExtension) {
|
||||||
throw new Error(`No vector extension found. Available extensions: ${VECTOR_EXTENSIONS.join(', ')}`);
|
throw new Error(`No vector extension found. Available extensions: ${VECTOR_EXTENSIONS.join(', ')}`);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user