From f33452ae8f444bfa05b64e8c3b591afa95e0d8e5 Mon Sep 17 00:00:00 2001 From: Tarun Pothulapati Date: Mon, 14 Mar 2022 21:22:32 +0000 Subject: [PATCH] [gitpod-db] add index on workspaceDB.Type Column For Telemetry queries to be less intensive on the CPU, We need to build Indexes to make the querying faster Signed-off-by: Tarun Pothulapati --- .../src/typeorm/entity/db-workspace.ts | 1 + .../1647290507971-IndexWorkspaceType.ts | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 components/gitpod-db/src/typeorm/migration/1647290507971-IndexWorkspaceType.ts diff --git a/components/gitpod-db/src/typeorm/entity/db-workspace.ts b/components/gitpod-db/src/typeorm/entity/db-workspace.ts index ff8e4ad337de07..fec2196d6266f4 100644 --- a/components/gitpod-db/src/typeorm/entity/db-workspace.ts +++ b/components/gitpod-db/src/typeorm/entity/db-workspace.ts @@ -68,6 +68,7 @@ export class DBWorkspace implements Workspace { }) shareable?: boolean; + @Index("ind_type") @Column({ default: "regular", }) diff --git a/components/gitpod-db/src/typeorm/migration/1647290507971-IndexWorkspaceType.ts b/components/gitpod-db/src/typeorm/migration/1647290507971-IndexWorkspaceType.ts new file mode 100644 index 00000000000000..06231adb3fa036 --- /dev/null +++ b/components/gitpod-db/src/typeorm/migration/1647290507971-IndexWorkspaceType.ts @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2022 Gitpod GmbH. All rights reserved. + * Licensed under the GNU Affero General Public License (AGPL). + * See License-AGPL.txt in the project root for license information. + */ + +import {MigrationInterface, QueryRunner} from "typeorm"; +import { indexExists } from "./helper/helper"; + +export class IndexWorkspaceType1647290507971 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + const TABLE_NAME = "d_b_workspace"; + const TYPE_INDEX_NAME = "ind_type"; + if (!(await indexExists(queryRunner, TABLE_NAME, TYPE_INDEX_NAME))) { + await queryRunner.query(`CREATE INDEX ${TYPE_INDEX_NAME} ON ${TABLE_NAME} (type)`); + } + } + + public async down(queryRunner: QueryRunner): Promise { + } + +}