From 5cc47b4f414026ecf16d8c7025571422367f7c58 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Fri, 26 Apr 2013 10:46:32 +0200 Subject: use last_modified column for finding new items (so we also see if they were updated or starred), use offset to paginate rather than item id --- db/itemmapper.php | 80 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 36 deletions(-) (limited to 'db/itemmapper.php') diff --git a/db/itemmapper.php b/db/itemmapper.php index 59654e62a..bef13ef4f 100644 --- a/db/itemmapper.php +++ b/db/itemmapper.php @@ -139,67 +139,65 @@ class ItemMapper extends Mapper implements IMapper { } - public function findAllNewFeed($id, $updatedSince, $status, $userId){ - $sql = 'AND `items`.`feed_id` = ? ' . - 'AND `items`.`id` >= ?'; - $sql = $this->makeSelectQueryStatus($sql, $status); - $params = array($userId, $id, $updatedSince); + public function findAllNew($updatedSince, $status, $userId){ + $sql = $this->makeSelectQueryStatus('AND `items`.`last_modified` >= ?', $status); + $params = array($userId, $updatedSince); return $this->findAllRows($sql, $params); } public function findAllNewFolder($id, $updatedSince, $status, $userId){ $sql = 'AND `feeds`.`folder_id` = ? ' . - 'AND `items`.`id` >= ?'; + 'AND `items`.`last_modified` >= ?'; $sql = $this->makeSelectQueryStatus($sql, $status); $params = array($userId, $id, $updatedSince); return $this->findAllRows($sql, $params); } - public function findAllNew($updatedSince, $status, $userId){ - $sql = $this->makeSelectQueryStatus('AND `items`.`id` >= ?', $status); - $params = array($userId, $updatedSince); + public function findAllNewFeed($id, $updatedSince, $status, $userId){ + $sql = 'AND `items`.`feed_id` = ? ' . + 'AND `items`.`last_modified` >= ?'; + $sql = $this->makeSelectQueryStatus($sql, $status); + $params = array($userId, $id, $updatedSince); return $this->findAllRows($sql, $params); } - public function findAllFeed($id, $limit, $offset, $status, $userId){ - $params = array($userId, $id); - $sql = 'AND `items`.`feed_id` = ? '; - if($offset !== 0){ - $sql .= 'AND `items`.`id` < ? '; - array_push($params, $offset); - } - $sql .= 'ORDER BY `items`.`id` DESC '; + public function findAll($limit, $offset, $newestItemId, $status, $userId){ + $sql = 'AND `items`.`id` < ? '; + $sql .= 'ORDER BY `items`.`pub_date` DESC, `items`.`id` DESC '; + $params = array($userId, $newestItemId); + $sql = $this->makeSelectQueryStatus($sql, $status); - return $this->findAllRows($sql, $params, $limit); + return $this->findAllRows($sql, $params, $limit, $offset); } - public function findAllFolder($id, $limit, $offset, $status, $userId){ - $params = array($userId, $id); - $sql = 'AND `feeds`.`folder_id` = ? '; - if($offset !== 0){ - $sql .= 'AND `items`.`id` < ? '; - array_push($params, $offset); - } - $sql .= 'ORDER BY `items`.`id` DESC '; + public function findAllFolder($id, $limit, $offset, $newestItemId, $status, + $userId){ + + $sql = 'AND `feeds`.`folder_id` = ? ' . + 'AND `items`.`id` < ? ' . + 'ORDER BY `items`.`pub_date` DESC, `items`.`id` DESC '; + $params = array($userId, $id, $newestItemId); + $sql = $this->makeSelectQueryStatus($sql, $status); - return $this->findAllRows($sql, $params, $limit); + + return $this->findAllRows($sql, $params, $limit, $offset); } - public function findAll($limit, $offset, $status, $userId){ - $params = array($userId); - $sql = ''; - if($offset !== 0){ - $sql .= 'AND `items`.`id` < ? '; - array_push($params, $offset); - } - $sql .= 'ORDER BY `items`.`id` DESC '; + public function findAllFeed($id, $limit, $offset, $newestItemId, $status, + $userId){ + + $sql = 'AND `items`.`feed_id` = ? ' . + 'AND `items`.`id` < ? ' . + 'ORDER BY `items`.`pub_date` DESC, `items`.`id` DESC '; $sql = $this->makeSelectQueryStatus($sql, $status); - return $this->findAllRows($sql, $params, $limit); + $params = array($userId, $id, $newestItemId); + + return $this->findAllRows($sql, $params, $limit, $offset); } @@ -248,6 +246,16 @@ class ItemMapper extends Mapper implements IMapper { } + public function getNewestItemId($userId) { + $sql = 'SELECT MAX(`items`.`id`) AS `max_id` FROM `*PREFIX*news_items` `items` '. + 'JOIN `*PREFIX*news_feeds` `feeds` ' . + 'ON `feeds`.`id` = `items`.`feed_id` '. + 'AND `feeds`.`user_id` = ?'; + $params = array($userId); + + $result = $this->findOneQuery($sql, $params); + return $result['max_id']; + } } -- cgit v1.2.3