mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(server): faster geodata import (#14241)
* faster geodata import * revert logging change * unlogged tables * leave spare connection * use expression index instead of generated column * do btree indexing with others
This commit is contained in:
parent
a3712e40bd
commit
ad510dd6fd
4 changed files with 213 additions and 137 deletions
|
|
@ -0,0 +1,29 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class NaturalEarthCountriesIdentityColumn1732072134943 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE naturalearth_countries ALTER id DROP DEFAULT`);
|
||||
await queryRunner.query(`DROP SEQUENCE naturalearth_countries_id_seq`);
|
||||
await queryRunner.query(`ALTER TABLE naturalearth_countries ALTER id ADD GENERATED ALWAYS AS IDENTITY`);
|
||||
|
||||
// same as ll_to_earth, but with explicit schema to avoid weirdness and allow it to work in expression indices
|
||||
await queryRunner.query(`
|
||||
CREATE 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
|
||||
$$`);
|
||||
|
||||
await queryRunner.query(`ALTER TABLE geodata_places DROP COLUMN "earthCoord"`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE naturalearth_countries ALTER id DROP GENERATED`);
|
||||
await queryRunner.query(`CREATE SEQUENCE naturalearth_countries_id_seq`);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE naturalearth_countries ALTER id SET DEFAULT nextval('naturalearth_countries_id_seq'::regclass)`,
|
||||
);
|
||||
await queryRunner.query(`DROP FUNCTION ll_to_earth_public`);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "geodata_places" ADD "earthCoord" earth GENERATED ALWAYS AS (ll_to_earth(latitude, longitude)) STORED`,
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue