Skip to content

Commit 11fa2f3

Browse files
authored
[db] DBWorkspace: add ind_basedOnPrebuildId (#18832)
1 parent f482e0a commit 11fa2f3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { MigrationInterface, QueryRunner } from "typeorm";
8+
import { indexExists } from "./helper/helper";
9+
10+
const TABLE_NAME = "d_b_workspace";
11+
const INDEX_NAME = "ind_basedOnPrebuildId";
12+
13+
export class WorkspaceIndexBasedOnPrebuildId1695888330735 implements MigrationInterface {
14+
public async up(queryRunner: QueryRunner): Promise<void> {
15+
if (!(await indexExists(queryRunner, TABLE_NAME, INDEX_NAME))) {
16+
await queryRunner.query(
17+
`ALTER TABLE \`${TABLE_NAME}\` ADD INDEX \`${INDEX_NAME}\` (basedOnPrebuildId), ALGORITHM=INPLACE, LOCK=NONE`,
18+
);
19+
}
20+
}
21+
22+
public async down(queryRunner: QueryRunner): Promise<void> {
23+
if (await indexExists(queryRunner, TABLE_NAME, INDEX_NAME)) {
24+
await queryRunner.query(`DROP INDEX ${INDEX_NAME} ON ${TABLE_NAME}`);
25+
}
26+
}
27+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
597597
LEFT OUTER JOIN d_b_workspace AS usages ON usages.basedOnPrebuildId = pb.id
598598
WHERE
599599
pb.buildworkspaceId = ws.id
600+
AND ws.type = 'prebuild'
600601
AND ws.contentDeletedTime = ''
601602
AND ws.pinned = 0
602603
AND ws.creationTime < NOW() - INTERVAL ? DAY

0 commit comments

Comments
 (0)