@@ -452,27 +452,28 @@ class RunServiceImpl(
452
452
453
453
workflowService.stopWorkflow(run)
454
454
455
- if (csmPlatformProperties.internalResultServices?.enabled == true )
456
- adminRunStorageTemplate.dropDB(run.id !! )
457
-
458
- runRepository.delete(run)
459
-
460
- val runs = listRuns(run.organizationId !! , run.workspaceId !! , run.runnerId !! , null , null )
461
- var lastRun : String? = null
462
- var lastStart : Long = 0
463
- if (runs.isNotEmpty()) {
464
- runs.forEach {
465
- if (it.createInfo.timestamp >= lastStart) {
466
- lastStart = it.createInfo.timestamp
467
- lastRun = it.id !!
455
+ val defaultPageSize = csmPlatformProperties.twincache.run.defaultPageSize
456
+ val pageRequest = PageRequest .ofSize(defaultPageSize )
457
+ val runs =
458
+ runRepository
459
+ .findByRunnerId(run.organizationId !! , run.workspaceId !! , run.runnerId !! , pageRequest)
460
+ .toList( )
461
+
462
+ val previousRuns = runs.filter { it.id != run.id }
463
+ val lastRun =
464
+ if (previousRuns.isEmpty()) {
465
+ null
466
+ } else {
467
+ previousRuns.maxBy { it.createInfo.timestamp }.id
468
468
}
469
- }
470
- } else {
471
- lastRun = null
472
- }
473
469
val runDeleted =
474
470
RunDeleted (this , run.organizationId, run.workspaceId, run.runnerId, run.id!! , lastRun)
475
471
this .eventPublisher.publishEvent(runDeleted)
472
+
473
+ if (csmPlatformProperties.internalResultServices?.enabled == true )
474
+ adminRunStorageTemplate.dropDB(run.id)
475
+
476
+ runRepository.delete(run)
476
477
} catch (exception: IllegalStateException ) {
477
478
logger.debug(
478
479
" An error occurred while deleting Run {}: {}" , run.id, exception.message, exception)
0 commit comments