From cc362bffd4faf1e339732b0a56bde3f58a7de5b1 Mon Sep 17 00:00:00 2001 From: "quentin.schmick" Date: Wed, 16 Mar 2022 10:54:27 -0400 Subject: [PATCH 1/2] Updated to pluck ids and perform delete using the ids --- src/Task.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Task.php b/src/Task.php index 4515d2e2..b17994ad 100644 --- a/src/Task.php +++ b/src/Task.php @@ -192,26 +192,38 @@ public function autoCleanup() { if ($this->auto_cleanup_num > 0) { if ($this->auto_cleanup_type === 'results') { - $oldest_id = self::results() + $oldest_id = $this->results() ->orderBy('ran_at', 'desc') ->limit($this->auto_cleanup_num) ->get() ->min('id'); do { - $rowsDeleted = self::results() + $rowsToDelete = $this->results() ->where('id', '<', $oldest_id) - ->limit(500) + ->limit(50) ->getQuery() + ->select('id') + ->pluck('id'); + + Result::query() + ->whereIn('id', $rowsToDelete) ->delete(); - } while ($rowsDeleted > 0); + + } while ($rowsToDelete > 0); } else { do { - $rowsDeleted = self::results() + $rowsToDelete = $this->results() ->where('ran_at', '<', Carbon::now()->subDays($this->auto_cleanup_num - 1)) - ->limit(500) + ->limit(50) ->getQuery() + ->select('id') + ->pluck('id'); + + Result::query() + ->whereIn('id', $rowsToDelete) ->delete(); - } while ($rowsDeleted > 0); + + } while ($rowsToDelete > 0); } } } From ffcaa7bbb63df0c50179fcf45d93580c5b3eae4d Mon Sep 17 00:00:00 2001 From: "quentin.schmick" Date: Thu, 17 Mar 2022 11:53:34 -0400 Subject: [PATCH 2/2] fixing style --- src/Task.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Task.php b/src/Task.php index b17994ad..12a066e3 100644 --- a/src/Task.php +++ b/src/Task.php @@ -208,7 +208,6 @@ public function autoCleanup() Result::query() ->whereIn('id', $rowsToDelete) ->delete(); - } while ($rowsToDelete > 0); } else { do { @@ -222,7 +221,6 @@ public function autoCleanup() Result::query() ->whereIn('id', $rowsToDelete) ->delete(); - } while ($rowsToDelete > 0); } }