Skip to content

Commit

Permalink
perf(Impact View): Concurrent Refresh on impact view
Browse files Browse the repository at this point in the history
Makes the Impact Materialized View able to be refreshed concurrently by adding an unique index
  • Loading branch information
KevSanchez authored and alexeh committed Nov 8, 2022
1 parent a31a77d commit 309d795
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class ImpactMaterializedViewUniqueIndex1667497567675
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP INDEX IF EXISTS idx_georegion_h3data_indexed;
CREATE UNIQUE INDEX idx_georegion_h3data_indexed ON impact_materialized_view ("geoRegionId", "h3DataId", "h3index") INCLUDE ("value");
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP INDEX IF EXISTS idx_georegion_h3data_indexed;
`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class IndicatorRecord extends TimestampedBaseEntity {

static updateImpactView(): Promise<void> {
return getManager().query(
`REFRESH MATERIALIZED VIEW ${IMPACT_VIEW_NAME} WITH DATA`,
`REFRESH MATERIALIZED VIEW CONCURRENTLY ${IMPACT_VIEW_NAME} WITH DATA`,
);
}
}

0 comments on commit 309d795

Please sign in to comment.