summaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-20 15:09:15 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-20 15:09:15 +0200
commit381f8efd1096001f34810414c1054a00a64179c8 (patch)
treea8bd92117dfd7352bfae3e06cacf57287312036a /db
parent4d4a27969705b8ff14c139795228d2f05e017b87 (diff)
set autopurge limit to 200 and purge per feed rather than per user or per all items, fix #98
Diffstat (limited to 'db')
-rw-r--r--db/itemmapper.php41
1 files changed, 27 insertions, 14 deletions
diff --git a/db/itemmapper.php b/db/itemmapper.php
index 326d58a2d..225cfb9b9 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -216,25 +216,38 @@ class ItemMapper extends Mapper implements IMapper {
}
- public function getReadOlderThanThreshold($threshold){
-
- // we want items that are not starred and not unread
+ /**
+ * Delete all items for feeds that have over $threshold unread and not
+ * starred items
+ */
+ public function deleteReadOlderThanThreshold($threshold){
$status = StatusFlag::STARRED | StatusFlag::UNREAD;
- $sql = 'SELECT * FROM `*PREFIX*news_items` ' .
- 'WHERE NOT ((`status` & ?) > 0)';
+ $sql = 'SELECT COUNT(*) `size`, `feed_id` ' .
+ 'FROM `*PREFIX*news_items` ' .
+ 'AND NOT ((`status` & ?) > 0) ' .
+ 'GROUP BY `feed_id` ' .
+ 'HAVING COUNT(*) > ?';
+ $params = array($status, $threshold);
+ $result = $this->execute($sql, $params);
+
+ while($row = $result->fetchRow()) {
+
+ $limit = $threshold - $row['size'];
+
+ if($limit > 0) {
+ $params = array($status, $row['feed_id']);
+
+ $sql = 'DELETE FROM `*PREFIX*news_items` `items` ' .
+ 'WHERE NOT ((`status` & ?) > 0) ' .
+ 'AND `feed_id` = ? ' .
+ 'ORDER BY `items`.`id` ASC';
- $params = array($status);
- return $this->findAllRows($sql, $params, $threshold);
+ $this->execute($sql, $params, $limit);
+ }
+ }
}
- public function deleteReadOlderThanId($id){
- $status = StatusFlag::STARRED | StatusFlag::UNREAD;
- $sql = 'DELETE FROM `*PREFIX*news_items` WHERE `id` < ? ' .
- 'AND NOT ((`status` & ?) > 0)';
- $params = array($id, $status);
- $this->execute($sql, $params);
- }
}