Skip to content

Commit 41c588b

Browse files
author
Quentin Schmick
authored
Updated to pluck ids and perform delete using the ids (#322)
* Updated to pluck ids and perform delete using the ids * fixing style
1 parent 7d159df commit 41c588b

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/Task.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,26 +192,36 @@ 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+
} while ($rowsToDelete > 0);
207212
} else {
208213
do {
209-
$rowsDeleted = self::results()
214+
$rowsToDelete = $this->results()
210215
->where('ran_at', '<', Carbon::now()->subDays($this->auto_cleanup_num - 1))
211-
->limit(500)
216+
->limit(50)
212217
->getQuery()
218+
->select('id')
219+
->pluck('id');
220+
221+
Result::query()
222+
->whereIn('id', $rowsToDelete)
213223
->delete();
214-
} while ($rowsDeleted > 0);
224+
} while ($rowsToDelete > 0);
215225
}
216226
}
217227
}

0 commit comments

Comments
 (0)