Skip to content

Commit cc362bf

Browse files
author
quentin.schmick
committed
Updated to pluck ids and perform delete using the ids
1 parent 7d159df commit cc362bf

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/Task.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,26 +192,38 @@ public function autoCleanup()
192192
{
193193
if ($this->auto_cleanup_num > 0) {
194194
if ($this->auto_cleanup_type === 'results') {
195-
$oldest_id = self::results()
195+
$oldest_id = $this->results()
196196
->orderBy('ran_at', 'desc')
197197
->limit($this->auto_cleanup_num)
198198
->get()
199199
->min('id');
200200
do {
201-
$rowsDeleted = self::results()
201+
$rowsToDelete = $this->results()
202202
->where('id', '<', $oldest_id)
203-
->limit(500)
203+
->limit(50)
204204
->getQuery()
205+
->select('id')
206+
->pluck('id');
207+
208+
Result::query()
209+
->whereIn('id', $rowsToDelete)
205210
->delete();
206-
} while ($rowsDeleted > 0);
211+
212+
} while ($rowsToDelete > 0);
207213
} else {
208214
do {
209-
$rowsDeleted = self::results()
215+
$rowsToDelete = $this->results()
210216
->where('ran_at', '<', Carbon::now()->subDays($this->auto_cleanup_num - 1))
211-
->limit(500)
217+
->limit(50)
212218
->getQuery()
219+
->select('id')
220+
->pluck('id');
221+
222+
Result::query()
223+
->whereIn('id', $rowsToDelete)
213224
->delete();
214-
} while ($rowsDeleted > 0);
225+
226+
} while ($rowsToDelete > 0);
215227
}
216228
}
217229
}

0 commit comments

Comments
 (0)