Skip to content

Commit cf38fac

Browse files
geroplroboquat
authored andcommitted
[db] Better index DBWorkspace
- ind_creationTime: creationTime - ind_contentDeletion: (contentDeletedTime, creationTime) - ind_softDeletion: (softDeletedTime, softDeleted)
1 parent 6081ee1 commit cf38fac

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

components/gitpod-db/src/typeorm/entity/db-workspace.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { TypeORM } from "../typeorm";
1111
import { Transformer } from "../transformer";
1212

1313
@Entity()
14+
@Index("ind_contentDeletion", ["contentDeletedTime", "creationTime"])
15+
@Index("ind_softDeletion", ["softDeletedTime", "softDeleted"])
1416
// on DB but not Typeorm: @Index("ind_lastModified", ["_lastModified"]) // DBSync
1517
export class DBWorkspace implements Workspace {
1618
@PrimaryColumn(TypeORM.WORKSPACE_ID_COLUMN_TYPE)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {MigrationInterface, QueryRunner} from "typeorm";
2+
import { indexExists } from "./helper/helper";
3+
4+
export class IndexWorkspaceGCQueries1637587650752 implements MigrationInterface {
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
const TABLE_NAME = "d_b_workspace";
8+
const CREATION_TIME_INDEX_NAME = "ind_creationTime";
9+
if (!(await indexExists(queryRunner, TABLE_NAME, CREATION_TIME_INDEX_NAME))) {
10+
await queryRunner.query(`CREATE INDEX ${CREATION_TIME_INDEX_NAME} ON ${TABLE_NAME} (creationTime)`);
11+
}
12+
13+
const CONTENT_DELETION_INDEX_NAME = "ind_contentDeletion";
14+
if (!(await indexExists(queryRunner, TABLE_NAME, CONTENT_DELETION_INDEX_NAME))) {
15+
await queryRunner.query(`CREATE INDEX ${CONTENT_DELETION_INDEX_NAME} ON ${TABLE_NAME} (contentDeletedTime, creationTime)`);
16+
}
17+
18+
const SOFT_DELETION_INDEX_NAME = "ind_softDeletion";
19+
if (!(await indexExists(queryRunner, TABLE_NAME, SOFT_DELETION_INDEX_NAME))) {
20+
await queryRunner.query(`CREATE INDEX ${SOFT_DELETION_INDEX_NAME} ON ${TABLE_NAME} (softDeletedTime, softDeleted)`);
21+
}
22+
}
23+
24+
public async down(queryRunner: QueryRunner): Promise<void> {
25+
}
26+
27+
}

0 commit comments

Comments
 (0)