summaryrefslogtreecommitdiffstats
path: root/db
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
parentdcf96e729991764e5dc5d5d9cc384540427dfdc4 (diff)
try to fix delete older than threshold so we can test it properly
Diffstat (limited to 'db')
-rw-r--r--db/itemmapper.php25
-rw-r--r--db/mapperfactory.php40
-rw-r--r--db/postgres/itemmapper.php69
3 files changed, 16 insertions, 118 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);
}
}
+
}
diff --git a/db/mapperfactory.php b/db/mapperfactory.php
deleted file mode 100644
index 6bc9346ca..000000000
--- a/db/mapperfactory.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
- * ownCloud - News
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
- */
-
-namespace OCA\News\Db;
-
-use \OCP\IDb;
-use \OCA\News\Db\Postgres\ItemMapper as PostgresItemMapper;
-
-class MapperFactory {
-
- private $dbType;
- private $db;
-
- public function __construct($dbType, IDb $db) {
- $this->dbType = $dbType;
- $this->db = $db;
- }
-
-
- public function getItemMapper() {
- switch($this->dbType) {
- case 'pgsql':
- return new PostgresItemMapper($this->db);
- default:
- return new ItemMapper($this->db);
- }
- }
-
-
-} \ No newline at end of file
diff --git a/db/postgres/itemmapper.php b/db/postgres/itemmapper.php
deleted file mode 100644
index f736fe54c..000000000
--- a/db/postgres/itemmapper.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-/**
- * ownCloud - News
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
- */
-
-namespace OCA\News\Db\Postgres;
-
-use \OCP\IDb;
-
-use \OCA\News\Db\StatusFlag;
-
-
-class ItemMapper extends \OCA\News\Db\ItemMapper {
-
- public function __construct(IDb $db){
- parent::__construct($db);
- }
-
-
- /**
- * 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 COUNT(*) - `feeds`.`articles_per_update` AS `size`, ' .
- '`items`.`feed_id` AS `feed_id` ' .
- '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` ' .
- 'HAVING COUNT(*) > ?';
- $params = [$status, $threshold];
- $result = $this->execute($sql, $params);
-
- while($row = $result->fetch()) {
-
- $size = (int) $row['size'];
- $limit = $size - $threshold;
-
- if($limit > 0) {
- $params = [$status, $row['feed_id'], $limit];
-
- $sql = 'DELETE FROM `*PREFIX*news_items` ' .
- '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);
- }
- }
-
- }
-
-
-} \ No newline at end of file