diff options
author | anoy <anoymouserver+github@mailbox.org> | 2021-02-01 21:15:30 +0100 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2021-02-02 13:48:55 +0100 |
commit | f2b74a0ba1e762185b82e92379ce9e7366230c1e (patch) | |
tree | 8e1cb7896ced547f4793e39ba23409ef62a8b80c /lib/Db/ItemMapperV2.php | |
parent | fb9a027ab51be77b04aeba3c74640f2c9e98f918 (diff) |
fix item purger for PostgreSQL
Signed-off-by: anoy <anoymouserver+github@mailbox.org>
Diffstat (limited to 'lib/Db/ItemMapperV2.php')
-rw-r--r-- | lib/Db/ItemMapperV2.php | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/Db/ItemMapperV2.php b/lib/Db/ItemMapperV2.php index 256621815..9b69cc9f2 100644 --- a/lib/Db/ItemMapperV2.php +++ b/lib/Db/ItemMapperV2.php @@ -149,7 +149,8 @@ class ItemMapperV2 extends NewsMapperV2 public function deleteOverThreshold(int $threshold, bool $removeUnread = false): ?int { $feedQb = $this->db->getQueryBuilder(); - $feedQb->addSelect('feed_id', $feedQb->func()->count('*', 'itemCount'), 'feeds.articles_per_update') + $feedQb->select('feed_id', $feedQb->func()->count('*', 'itemCount')) + ->addSelect($feedQb->func()->max('feeds.articles_per_update', 'articlesPerUpdate')) ->from($this->tableName, 'items') ->innerJoin('items', FeedMapperV2::TABLE_NAME, 'feeds', 'items.feed_id = feeds.id') ->groupBy('feed_id'); @@ -165,11 +166,11 @@ class ItemMapperV2 extends NewsMapperV2 $rangeQuery->select('id') ->from($this->tableName) ->where('feed_id = :feedId') - ->andWhere('starred = 0') + ->andWhere('starred = false') ->orderBy('updated_date', 'DESC'); if ($removeUnread === false) { - $rangeQuery->andWhere('unread = 0'); + $rangeQuery->andWhere('unread = false'); } $total_items = []; @@ -178,7 +179,7 @@ class ItemMapperV2 extends NewsMapperV2 continue; } - $rangeQuery->setFirstResult(max($threshold, $feed['articles_per_update'])); + $rangeQuery->setFirstResult(max($threshold, $feed['articlesPerUpdate'])); $items = $this->db->executeQuery($rangeQuery->getSQL(), ['feedId' => $feed['feed_id']]) ->fetchAll(FetchMode::COLUMN); @@ -190,7 +191,16 @@ class ItemMapperV2 extends NewsMapperV2 $deleteQb->delete($this->tableName) ->where('id IN (?)'); - return $this->db->executeUpdate($deleteQb->getSQL(), [$total_items], [IQueryBuilder::PARAM_INT_ARRAY]); + $affected_rows = 0; + // split $total_items into multiple chunks because of the parameter limit + foreach (array_chunk($total_items, NewsMapperV2::PDO_PARAMS_LIMIT) as $items_chunk) { + $affected_rows += $this->db->executeUpdate( + $deleteQb->getSQL(), + [$items_chunk], + [IQueryBuilder::PARAM_INT_ARRAY] + ); + } + return $affected_rows; } /** |