From 3c5762691827fae90d81ed05eee163da90140784 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 17 Jan 2016 08:12:44 -0500 Subject: Replace raw SQL query by PicoDb --- app/Model/ProjectActivity.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'app/Model/ProjectActivity.php') diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php index 309bab9a..d3aeefe5 100644 --- a/app/Model/ProjectActivity.php +++ b/app/Model/ProjectActivity.php @@ -169,14 +169,8 @@ class ProjectActivity extends Base public function cleanup($max) { if ($this->db->table(self::TABLE)->count() > $max) { - $this->db->execute(' - DELETE FROM '.self::TABLE.' - WHERE id <= ( - SELECT id FROM ( - SELECT id FROM '.self::TABLE.' ORDER BY id DESC LIMIT 1 OFFSET '.$max.' - ) foo - )' - ); + $subquery = $this->db->table(self::TABLE)->desc('id')->limit($max)->columns('id'); + $this->db->table(self::TABLE)->notInSubquery('id', $subquery)->remove(); } } -- cgit v1.2.3 From e7a614781985a5686092d62a48021066dc559e35 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 17 Jan 2016 15:27:18 -0500 Subject: Fix regression: make sql query compatible with Mysql --- app/Model/ProjectActivity.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/Model/ProjectActivity.php') diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php index d3aeefe5..74df26a1 100644 --- a/app/Model/ProjectActivity.php +++ b/app/Model/ProjectActivity.php @@ -168,9 +168,11 @@ class ProjectActivity extends Base */ public function cleanup($max) { - if ($this->db->table(self::TABLE)->count() > $max) { - $subquery = $this->db->table(self::TABLE)->desc('id')->limit($max)->columns('id'); - $this->db->table(self::TABLE)->notInSubquery('id', $subquery)->remove(); + $total = $this->db->table(self::TABLE)->count(); + + if ($total > $max) { + $ids = $this->db->table(self::TABLE)->asc('id')->limit($total - $max)->findAllByColumn('id'); + $this->db->table(self::TABLE)->in('id', $ids)->remove(); } } -- cgit v1.2.3