@@ -158,7 +158,7 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
158
158
. addOrderBy ( 'GREATEST(ws.creationTime, wsi.creationTime, wsi.startedTime, wsi.stoppedTime)' , 'DESC' )
159
159
. limit ( options . limit || 10 ) ;
160
160
if ( options . searchString ) {
161
- qb . andWhere ( "ws.description LIKE :searchString" , { searchString : `%${ options . searchString } %` } ) ;
161
+ qb . andWhere ( "ws.description LIKE :searchString" , { searchString : `%${ options . searchString } %` } ) ;
162
162
}
163
163
if ( ! options . includeHeadless ) {
164
164
qb . andWhere ( "ws.type = 'regular'" ) ;
@@ -334,6 +334,15 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
334
334
return { total, rows } ;
335
335
}
336
336
337
+ public async getInstanceCount ( type ?: string ) : Promise < number > {
338
+ const workspaceInstanceRepo = await this . getWorkspaceInstanceRepo ( ) ;
339
+ const queryBuilder = workspaceInstanceRepo . createQueryBuilder ( "wsi" )
340
+ . leftJoinAndMapOne ( "wsi.workspace" , DBWorkspace , "ws" , "wsi.workspaceId = ws.id" )
341
+ . where ( "ws.type = :type" , { type : type ? type . toString ( ) : "regular" } ) ; // only regular workspaces by default
342
+
343
+ return await queryBuilder . getCount ( ) ;
344
+ }
345
+
337
346
public async findRegularRunningInstances ( userId ?: string ) : Promise < WorkspaceInstance [ ] > {
338
347
const infos = await this . findRunningInstancesWithWorkspaces ( undefined , userId ) ;
339
348
return infos . filter (
@@ -578,7 +587,7 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
578
587
579
588
public async findSnapshotsByWorkspaceId ( workspaceId : string ) : Promise < Snapshot [ ] > {
580
589
const snapshots = await this . getSnapshotRepo ( ) ;
581
- return snapshots . find ( { where : { originalWorkspaceId : workspaceId } } ) ;
590
+ return snapshots . find ( { where : { originalWorkspaceId : workspaceId } } ) ;
582
591
}
583
592
584
593
public async storePrebuiltWorkspace ( pws : PrebuiltWorkspace ) : Promise < PrebuiltWorkspace > {
@@ -596,7 +605,7 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
596
605
}
597
606
const repo = await this . getPrebuiltWorkspaceRepo ( ) ;
598
607
return await repo . createQueryBuilder ( 'pws' )
599
- . where ( 'pws.cloneURL = :cloneURL AND pws.commit LIKE :commit' , { cloneURL, commit : commit + '%' } )
608
+ . where ( 'pws.cloneURL = :cloneURL AND pws.commit LIKE :commit' , { cloneURL, commit : commit + '%' } )
600
609
. orderBy ( 'pws.creationTime' , 'DESC' )
601
610
. innerJoinAndMapOne ( 'pws.workspace' , DBWorkspace , 'ws' , "pws.buildWorkspaceId = ws.id and ws.contentDeletedTime = ''" )
602
611
. getOne ( ) ;
@@ -737,7 +746,13 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
737
746
return { total, rows } ;
738
747
}
739
748
749
+ public async getWorkspaceCount ( type ?: String ) : Promise < Number > {
750
+ const workspaceRepo = await this . getWorkspaceRepo ( ) ;
751
+ const queryBuilder = workspaceRepo . createQueryBuilder ( "ws" )
752
+ . where ( "ws.type = :type" , { type : type ? type . toString ( ) : "regular" } ) ; // only regular workspaces by default
740
753
754
+ return await queryBuilder . getCount ( ) ;
755
+ }
741
756
742
757
public async findAllWorkspaceAndInstances ( offset : number , limit : number , orderBy : keyof WorkspaceAndInstance , orderDir : "ASC" | "DESC" , query ?: AdminGetWorkspacesQuery , searchTerm ?: string ) : Promise < { total : number , rows : WorkspaceAndInstance [ ] } > {
743
758
let whereConditions = [ ] ;
@@ -827,7 +842,7 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
827
842
const workspaceRepo = await this . getWorkspaceRepo ( ) ;
828
843
const workspace = await workspaceRepo . findOne ( id ) ;
829
844
if ( ! workspace ) {
830
- return ;
845
+ return ;
831
846
}
832
847
833
848
const instance = await this . findCurrentInstance ( id ) ;
@@ -899,7 +914,7 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
899
914
} ) ;
900
915
}
901
916
902
- async findPrebuildInfos ( prebuildIds : string [ ] ) : Promise < PrebuildInfo [ ] > {
917
+ async findPrebuildInfos ( prebuildIds : string [ ] ) : Promise < PrebuildInfo [ ] > {
903
918
const repo = await this . getPrebuildInfoRepo ( ) ;
904
919
905
920
const query = repo . createQueryBuilder ( 'pi' ) ;
@@ -908,7 +923,7 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
908
923
if ( filteredIds . length === 0 ) {
909
924
return [ ] ;
910
925
}
911
- query . andWhere ( `pi.prebuildId in (${ filteredIds . map ( id => `'${ id } '` ) . join ( ", " ) } )` )
926
+ query . andWhere ( `pi.prebuildId in (${ filteredIds . map ( id => `'${ id } '` ) . join ( ", " ) } )` )
912
927
913
928
const res = await query . getMany ( ) ;
914
929
return res . map ( r => r . info ) ;
0 commit comments