Skip to content

Commit f286566

Browse files
committed
Remove filtering for only non-running workspaces
1 parent 743ae10 commit f286566

File tree

2 files changed

+19
-40
lines changed

2 files changed

+19
-40
lines changed

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

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
PrebuildWithWorkspace,
3737
PrebuildWithWorkspaceAndInstances,
3838
PrebuiltUpdatableAndWorkspace,
39+
WorkspaceAndOwner,
3940
WorkspaceDB,
4041
WorkspaceOwnerAndContentDeletedTime,
4142
WorkspaceOwnerAndDeletionEligibility,
@@ -492,39 +493,25 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
492493
throw new Error("cutOffDate must not be in the future, was: " + cutOffDate.toISOString());
493494
}
494495
const workspaceRepo = await this.getWorkspaceRepo();
495-
const qb = workspaceRepo
496-
.createQueryBuilder("ws")
497-
.leftJoinAndMapOne(
498-
"ws.latestInstance",
499-
DBWorkspaceInstance,
500-
"wsi",
501-
`wsi.id = (
502-
SELECT i.id
503-
FROM d_b_workspace_instance AS i
504-
WHERE i.workspaceId = ws.id
505-
ORDER BY i.creationTime DESC
506-
LIMIT 1
507-
)`,
508-
)
509-
.select(["ws.id", "ws.ownerId", "ws.deletionEligibilityTime", "wsi.id", "wsi.status"])
510-
.where("ws.deleted = :deleted", { deleted: 0 })
511-
.andWhere("ws.type = :type", { type })
512-
.andWhere("ws.softDeleted IS NULL")
513-
.andWhere("ws.softDeletedTime = ''")
514-
.andWhere("ws.pinned = :pinned", { pinned: 0 })
515-
.andWhere("ws.deletionEligibilityTime != ''")
516-
.andWhere("ws.deletionEligibilityTime < :cutOffDate", { cutOffDate: cutOffDate.toISOString() })
517-
// we don't want to delete workspaces that are active
518-
.andWhere(
519-
new Brackets((qb) => {
520-
qb.where("wsi.id IS NULL").orWhere("JSON_UNQUOTE(wsi.status->>'$.phase') = :stoppedStatus", {
521-
stoppedStatus: "stopped",
522-
});
523-
}),
524-
)
525-
.limit(limit);
496+
const dbResults = await workspaceRepo.query(
497+
`
498+
SELECT ws.id AS id,
499+
ws.ownerId AS ownerId,
500+
ws.deletionEligibilityTime AS deletionEligibilityTime
501+
FROM d_b_workspace AS ws
502+
WHERE ws.deleted = 0
503+
AND ws.type = ?
504+
AND ws.softDeleted IS NULL
505+
AND ws.softDeletedTime = ''
506+
AND ws.pinned = 0
507+
AND ws.deletionEligibilityTime != ''
508+
AND ws.deletionEligibilityTime < ?
509+
LIMIT ?;
510+
`,
511+
[type, cutOffDate.toISOString(), limit],
512+
);
526513

527-
return qb.getMany();
514+
return dbResults as WorkspaceAndOwner[];
528515
}
529516

530517
public async findWorkspacesForPurging(

components/gitpod-db/src/workspace-db.spec.db.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,6 @@ class WorkspaceDBSpec {
361361
expect(dbResult.length).to.eq(0);
362362
}
363363

364-
@test(timeout(10000))
365-
public async testFindEligibleWorkspacesForSoftDeletion_notMarkedEligibleRunningInstance() {
366-
this.ws.deletionEligibilityTime = this.timeWs;
367-
await Promise.all([this.db.store(this.ws), this.db.storeInstance(this.wsi1), this.db.storeInstance(this.wsi2)]);
368-
const dbResult = await this.db.findEligibleWorkspacesForSoftDeletion(new Date(this.timeAfter), 10);
369-
expect(dbResult.length).to.eq(0);
370-
}
371-
372364
@test(timeout(10000))
373365
public async testFindAllWorkspaceAndInstances_workspaceId() {
374366
await Promise.all([

0 commit comments

Comments
 (0)