Skip to content

Commit 888d7a9

Browse files
CusorBot Fix: use subquery instead of loading all IDs into memory
1 parent dfa1502 commit 888d7a9

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

ProcessMaker/Jobs/EvaluateProcessRetentionJob.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ public function handle(): void
5555
? Carbon::parse($process->properties['retention_updated_at'])
5656
: Carbon::now();
5757

58-
// Get all process request IDs for this process
59-
$processRequestIds = ProcessRequest::where('process_id', $this->processId)->pluck('id');
60-
61-
// If there are no process requests, nothing to delete
62-
if ($processRequestIds->isEmpty()) {
58+
// Check if there are any process requests for this process
59+
// If not, nothing to delete
60+
if (!ProcessRequest::where('process_id', $this->processId)->exists()) {
6361
return;
6462
}
6563

@@ -77,7 +75,10 @@ public function handle(): void
7775
// For cases created after retention_updated_at: cutoff is now - retention_period
7876
$newCasesCutoff = $now->copy()->subMonths($retentionMonths);
7977

80-
CaseNumber::whereIn('process_request_id', $processRequestIds)
78+
// Use subquery to get process request IDs
79+
$processRequestSubquery = ProcessRequest::where('process_id', $this->processId)->select('id');
80+
81+
CaseNumber::whereIn('process_request_id', $processRequestSubquery)
8182
->where(function ($query) use ($retentionUpdatedAt, $oldCasesCutoff, $newCasesCutoff) {
8283
// Cases created before retention_updated_at: delete if created before (retention_updated_at - retention_period)
8384
$query->where(function ($q) use ($retentionUpdatedAt, $oldCasesCutoff) {

0 commit comments

Comments
 (0)