summaryrefslogtreecommitdiffstats
path: root/db/itemmapper.php
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-11-06 15:49:16 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2014-11-06 15:49:16 +0100
commita600f6b718ab81efeda1fce68e5f817c3f23504a (patch)
treedc7521e1a9e9ee767602addef42e56d00861c6c1 /db/itemmapper.php
parentdcf96e729991764e5dc5d5d9cc384540427dfdc4 (diff)
try to fix delete older than threshold so we can test it properly
Diffstat (limited to 'db/itemmapper.php')
-rw-r--r--db/itemmapper.php25
1 files changed, 16 insertions, 9 deletions
diff --git a/db/itemmapper.php b/db/itemmapper.php
index 41c2a6975..dec80894f 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -237,15 +237,17 @@ class ItemMapper extends NewsMapper {
*/
public function deleteReadOlderThanThreshold($threshold){
$status = StatusFlag::STARRED | StatusFlag::UNREAD;
- $sql = 'SELECT COUNT(*) - `feeds`.`articles_per_update` AS `size`, ' .
- '`items`.`feed_id` AS `feed_id` ' .
+ $params = [$status, $threshold];
+
+ $sql = 'SELECT (COUNT(*) - `feeds`.`articles_per_update`) AS `size`, ' .
+ '`feeds`.`id` AS `feed_id`, `feeds`.`articles_per_update` ' .
'FROM `*PREFIX*news_items` `items` ' .
'JOIN `*PREFIX*news_feeds` `feeds` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
'AND NOT ((`items`.`status` & ?) > 0) ' .
- 'GROUP BY `items`.`feed_id`, `feeds`.`articles_per_update` ' .
+ 'GROUP BY `feeds`.`id`, `feeds`.`articles_per_update` ' .
'HAVING COUNT(*) > ?';
- $params = [$status, $threshold];
+
$result = $this->execute($sql, $params);
while($row = $result->fetch()) {
@@ -254,16 +256,21 @@ class ItemMapper extends NewsMapper {
$limit = $size - $threshold;
if($limit > 0) {
- $params = [$status, $row['feed_id']];
+ $params = [$status, $row['feed_id'], $limit];
$sql = 'DELETE FROM `*PREFIX*news_items` ' .
- 'WHERE NOT ((`status` & ?) > 0) ' .
- 'AND `feed_id` = ? ' .
- 'ORDER BY `id` ASC';
+ 'WHERE `id` IN (' .
+ 'SELECT `id` FROM `*PREFIX*news_items` ' .
+ 'WHERE NOT ((`status` & ?) > 0) ' .
+ 'AND `feed_id` = ? ' .
+ 'ORDER BY `id` ASC ' .
+ 'LIMIT ?' .
+ ')';
- $this->execute($sql, $params, $limit);
+ $this->execute($sql, $params);
}
}
+
}