mirror of
https://github.com/immich-app/immich.git
synced 2025-01-22 11:42:46 +01:00
tweaks
This commit is contained in:
parent
876893c823
commit
259f5d127d
2 changed files with 36 additions and 24 deletions
|
@ -0,0 +1,17 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class RemoveStrictKeywordFromEarthFunction1732128889378 implements MigrationInterface {
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
CREATE OR REPLACE FUNCTION ll_to_earth_public(latitude double precision, longitude double precision) RETURNS public.earth PARALLEL SAFE IMMUTABLE LANGUAGE SQL AS $$
|
||||||
|
SELECT public.cube(public.cube(public.cube(public.earth()*cos(radians(latitude))*cos(radians(longitude))),public.earth()*cos(radians(latitude))*sin(radians(longitude))),public.earth()*sin(radians(latitude)))::public.earth
|
||||||
|
$$`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
CREATE OR REPLACE FUNCTION ll_to_earth_public(latitude double precision, longitude double precision) RETURNS public.earth PARALLEL SAFE IMMUTABLE STRICT LANGUAGE SQL AS $$
|
||||||
|
SELECT public.cube(public.cube(public.cube(public.earth()*cos(radians(latitude))*cos(radians(longitude))),public.earth()*cos(radians(latitude))*sin(radians(longitude))),public.earth()*sin(radians(latitude)))::public.earth
|
||||||
|
$$`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -218,8 +218,26 @@ export class MapRepository implements IMapRepository {
|
||||||
await this.dataSource.query(
|
await this.dataSource.query(
|
||||||
'CREATE UNLOGGED TABLE geodata_places_tmp (LIKE geodata_places INCLUDING ALL EXCLUDING INDEXES)',
|
'CREATE UNLOGGED TABLE geodata_places_tmp (LIKE geodata_places INCLUDING ALL EXCLUDING INDEXES)',
|
||||||
);
|
);
|
||||||
|
await this.dataSource.query(`
|
||||||
|
CREATE INDEX IDX_geodata_gist_earthcoord_${randomUUID().replaceAll('-', '_')}
|
||||||
|
ON geodata_places_tmp
|
||||||
|
USING gist (ll_to_earth_public(latitude, longitude))`);
|
||||||
await this.loadCities500(admin1, admin2);
|
await this.loadCities500(admin1, admin2);
|
||||||
await this.createGeodataIndices();
|
await Promise.all([
|
||||||
|
this.dataSource.query('ALTER TABLE geodata_places_tmp ADD PRIMARY KEY (id) WITH (FILLFACTOR = 100)'),
|
||||||
|
this.dataSource.query(`
|
||||||
|
CREATE INDEX idx_geodata_places_name_${randomUUID().replaceAll('-', '_')}
|
||||||
|
ON geodata_places_tmp
|
||||||
|
USING gin (f_unaccent(name) gin_trgm_ops)`),
|
||||||
|
this.dataSource.query(`
|
||||||
|
CREATE INDEX idx_geodata_places_admin1_name_${randomUUID().replaceAll('-', '_')}
|
||||||
|
ON geodata_places_tmp
|
||||||
|
USING gin (f_unaccent("admin1Name") gin_trgm_ops)`),
|
||||||
|
this.dataSource.query(`
|
||||||
|
CREATE INDEX idx_geodata_places_admin2_name_${randomUUID().replaceAll('-', '_')}
|
||||||
|
ON geodata_places_tmp
|
||||||
|
USING gin (f_unaccent("admin2Name") gin_trgm_ops)`),
|
||||||
|
]);
|
||||||
|
|
||||||
await this.dataSource.transaction(async (manager) => {
|
await this.dataSource.transaction(async (manager) => {
|
||||||
await manager.query('ALTER TABLE geodata_places RENAME TO geodata_places_old');
|
await manager.query('ALTER TABLE geodata_places RENAME TO geodata_places_old');
|
||||||
|
@ -300,27 +318,4 @@ export class MapRepository implements IMapRepository {
|
||||||
|
|
||||||
return adminMap;
|
return adminMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private createGeodataIndices() {
|
|
||||||
return Promise.all([
|
|
||||||
this.dataSource.query(`ALTER TABLE geodata_places_tmp ADD PRIMARY KEY (id) WITH (FILLFACTOR = 100)`),
|
|
||||||
this.dataSource.query(`
|
|
||||||
CREATE INDEX IDX_geodata_gist_earthcoord_${randomUUID().replaceAll('-', '_')}
|
|
||||||
ON geodata_places_tmp
|
|
||||||
USING gist (ll_to_earth_public(latitude, longitude))
|
|
||||||
WITH (fillfactor = 100)`),
|
|
||||||
this.dataSource.query(`
|
|
||||||
CREATE INDEX idx_geodata_places_name_${randomUUID().replaceAll('-', '_')}
|
|
||||||
ON geodata_places_tmp
|
|
||||||
USING gin (f_unaccent(name) gin_trgm_ops)`),
|
|
||||||
this.dataSource.query(`
|
|
||||||
CREATE INDEX idx_geodata_places_admin1_name_${randomUUID().replaceAll('-', '_')}
|
|
||||||
ON geodata_places_tmp
|
|
||||||
USING gin (f_unaccent("admin1Name") gin_trgm_ops)`),
|
|
||||||
this.dataSource.query(`
|
|
||||||
CREATE INDEX idx_geodata_places_admin2_name_${randomUUID().replaceAll('-', '_')}
|
|
||||||
ON geodata_places_tmp
|
|
||||||
USING gin (f_unaccent("admin2Name") gin_trgm_ops)`),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue