@@ -52,6 +52,7 @@ import { DBPrebuiltWorkspace } from "./entity/db-prebuilt-workspace";
52
52
import { DBPrebuiltWorkspaceUpdatable } from "./entity/db-prebuilt-workspace-updatable" ;
53
53
import { BUILTIN_WORKSPACE_PROBE_USER_ID } from "../user-db" ;
54
54
import { DBPrebuildInfo } from "./entity/db-prebuild-info-entry" ;
55
+ import { daysBefore } from "@gitpod/gitpod-protocol/lib/util/timeutil" ;
55
56
56
57
type RawTo < T > = ( instance : WorkspaceInstance , ws : Workspace ) => T ;
57
58
interface OrderBy {
@@ -592,6 +593,22 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
592
593
return dbResults as WorkspaceAndOwner [ ] ;
593
594
}
594
595
596
+ public async findWorkspacesForPurging (
597
+ minContentDeletionTimeInDays : number ,
598
+ limit : number ,
599
+ now : Date ,
600
+ ) : Promise < WorkspaceAndOwner [ ] > {
601
+ const minPurgeTime = daysBefore ( now . toISOString ( ) , minContentDeletionTimeInDays ) ;
602
+ const repo = await this . getWorkspaceRepo ( ) ;
603
+ const qb = repo
604
+ . createQueryBuilder ( "ws" )
605
+ . select ( [ "ws.id" , "ws.ownerId" ] )
606
+ . where ( `ws.contentDeletedTime != ''` )
607
+ . andWhere ( `ws.contentDeletedTime < :minPurgeTime` , { minPurgeTime } )
608
+ . limit ( limit ) ;
609
+ return await qb . getMany ( ) ;
610
+ }
611
+
595
612
public async findWorkspacesForContentDeletion (
596
613
minSoftDeletedTimeInDays : number ,
597
614
limit : number ,
@@ -964,8 +981,8 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
964
981
* around to deleting them.
965
982
*/
966
983
public async hardDeleteWorkspace ( workspaceId : string ) : Promise < void > {
967
- await ( await this . getWorkspaceRepo ( ) ) . update ( workspaceId , { deleted : true } ) ;
968
984
await ( await this . getWorkspaceInstanceRepo ( ) ) . update ( { workspaceId } , { deleted : true } ) ;
985
+ await ( await this . getWorkspaceRepo ( ) ) . update ( workspaceId , { deleted : true } ) ;
969
986
}
970
987
971
988
public async findAllWorkspaces (
0 commit comments