From ee2c1a8c7888ef16d76a0c03ff2040aaa8a11a94 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 28 Nov 2013 01:42:06 +0100 Subject: Classement par date d'ajout e.id (expérimentation) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Expérimentation : classement par date d'ajout dans la base plutôt que selon la date déclarée par le flux (qui est parfois fausse dans le passé, dans le futur, ou absente). Quelques conséquences : * Les flux avec des dates erronées ne sont plus un problème * Lorsqu'on fait "marquer tout comme lu", les articles arrivés pendant la lecture ne sont plus indûment marqués comme lus * Les articles ont tendance à être plus regroupés par flux lorsqu'on les affiche par catégorie * Si un utilisateur n'utilise pas de cron et n'utilise pas FreshRSS pendant plusieurs jours, lors du rafraîchissement, les nouveaux articles seront dans "Aujourd'hui" (à interpréter donc comme les articles reçus aujourd'hui, et non comme déclarés comme étant publiés aujourd'hui) * La pagination est plus efficace Termine l'implémentation de https://github.com/marienfressinaud/FreshRSS/issues/202 --- app/controllers/entryController.php | 8 +++--- app/controllers/feedController.php | 11 ++++++++ app/layout/nav_menu.phtml | 11 ++++---- app/models/Entry.php | 50 ++++++++++++++++++------------------- app/models/Feed.php | 10 -------- app/models/RSSPaginator.php | 4 +++ 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/app/controllers/entryController.php b/app/controllers/entryController.php index 8016d719f..fa34ad429 100755 --- a/app/controllers/entryController.php +++ b/app/controllers/entryController.php @@ -36,23 +36,23 @@ class entryController extends ActionController { $is_read = Request::param ('is_read'); $get = Request::param ('get'); $nextGet = Request::param ('nextGet', $get); - $dateMax = Request::param ('dateMax', 0); + $idMax = Request::param ('idMax', 0); $is_read = !!$is_read; $entryDAO = new EntryDAO (); if ($id == false) { if (!$get) { - $entryDAO->markReadEntries ($dateMax); + $entryDAO->markReadEntries ($idMax); } else { $typeGet = $get[0]; $get = substr ($get, 2); if ($typeGet == 'c') { - $entryDAO->markReadCat ($get, $dateMax); + $entryDAO->markReadCat ($get, $idMax); $this->params = array ('get' => $nextGet); } elseif ($typeGet == 'f') { - $entryDAO->markReadFeed ($get, $dateMax); + $entryDAO->markReadFeed ($get, $idMax); $this->params = array ('get' => $nextGet); } } diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php index 8b3667668..cd252b086 100755 --- a/app/controllers/feedController.php +++ b/app/controllers/feedController.php @@ -20,6 +20,15 @@ class feedController extends ActionController { $this->catDAO->checkDefault (); } + private static function entryDateComparer($e1, $e2) { + $d1 = $e1->date(true); + $d2 = $e2->date(true); + if ($d1 === $d2) { + return 0; + } + return ($d1 < $d2) ? -1 : 1; + } + public function addAction () { if (Request::isPost ()) { $url = Request::param ('url_rss'); @@ -75,6 +84,7 @@ class feedController extends ActionController { } else { $entryDAO = new EntryDAO (); $entries = $feed->entries (); + usort($entries, 'self::entryDateComparer'); // on calcule la date des articles les plus anciens qu'on accepte $nb_month_old = $this->view->conf->oldEntries (); @@ -173,6 +183,7 @@ class feedController extends ActionController { try { $feed->load (); $entries = $feed->entries (); + usort($entries, 'self::entryDateComparer'); //For this feed, check last n entry GUIDs already in database $existingGuids = array_fill_keys ($entryDAO->listLastGuidsByFeed ($feed->id (), count($entries) + 10), 1); diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index 890f80f64..0b95b4b02 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -18,6 +18,8 @@ $string_mark = Translate::t ('mark_cat_read'); } $nextGet = $get; + $p = $this->entryPaginator->peek(); + $idMax = $p === null ? '0' : $p->id(); if (($this->conf->onread_jump_next () === 'yes') && (strlen ($get) > 2)) { $anotherUnreadId = ''; $foundCurrent = false; @@ -53,7 +55,7 @@ break; } } - $markReadUrl = _url ('entry', 'read', 'is_read', 1, 'get', $get, 'nextGet', $nextGet); + $markReadUrl = _url ('entry', 'read', 'is_read', 1, 'get', $get, 'nextGet', $nextGet, 'idMax', $idMax); Session::_param ('markReadUrl', $markReadUrl); ?> @@ -69,12 +71,11 @@
  • -
  • -
  • +
  • +
  • diff --git a/app/models/Entry.php b/app/models/Entry.php index 636e67e75..80e8d7b6e 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -140,17 +140,17 @@ class Entry extends Model { } public function isDay ($day) { - $date = getdate (); - $today = mktime (0, 0, 0, $date['mon'], $date['mday'], $date['year']); + $date = $this->dateAdded(true); + $today = strtotime('today'); $yesterday = $today - 86400; - if ($day == Days::TODAY && - $this->date >= $today && $this->date < $today + 86400) { + if ($day === Days::TODAY && + $date >= $today && $date < $today + 86400) { return true; - } elseif ($day == Days::YESTERDAY && - $this->date >= $yesterday && $this->date < $yesterday + 86400) { + } elseif ($day === Days::YESTERDAY && + $date >= $yesterday && $date < $yesterday + 86400) { return true; - } elseif ($day == Days::BEFORE_YESTERDAY && $this->date < $yesterday) { + } elseif ($day === Days::BEFORE_YESTERDAY && $date < $yesterday) { return true; } else { return false; @@ -287,8 +287,8 @@ class EntryDAO extends Model_pdo { return false; } } - public function markReadEntries ($dateMax = 0) { - if ($dateMax === 0) { + public function markReadEntries ($idMax = 0) { + if ($idMax === 0) { $sql = 'UPDATE ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id ' . 'SET e.is_read = 1, f.cache_nbUnreads=0 ' . 'WHERE e.is_read = 0 AND f.priority > 0'; @@ -305,8 +305,8 @@ class EntryDAO extends Model_pdo { $sql = 'UPDATE ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id ' . 'SET e.is_read = 1 ' - . 'WHERE e.is_read = 0 AND e.date < ? AND f.priority > 0'; - $values = array ($dateMax); + . 'WHERE e.is_read = 0 AND e.id <= ? AND f.priority > 0'; + $values = array ($idMax); $stm = $this->bd->prepare ($sql); if (!($stm && $stm->execute ($values))) { $info = $stm->errorInfo(); @@ -339,8 +339,8 @@ class EntryDAO extends Model_pdo { return $affected; } } - public function markReadCat ($id, $dateMax = 0) { - if ($dateMax === 0) { + public function markReadCat ($id, $idMax = 0) { + if ($idMax === 0) { $sql = 'UPDATE ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id ' . 'SET e.is_read = 1, f.cache_nbUnreads=0 ' . 'WHERE f.category = ? AND e.is_read = 0'; @@ -358,8 +358,8 @@ class EntryDAO extends Model_pdo { $sql = 'UPDATE ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id ' . 'SET e.is_read = 1 ' - . 'WHERE f.category = ? AND e.is_read = 0 AND e.date < ?'; - $values = array ($id, $dateMax); + . 'WHERE f.category = ? AND e.is_read = 0 AND e.id <= ?'; + $values = array ($id, $idMax); $stm = $this->bd->prepare ($sql); if (!($stm && $stm->execute ($values))) { $info = $stm->errorInfo(); @@ -394,8 +394,8 @@ class EntryDAO extends Model_pdo { return $affected; } } - public function markReadFeed ($id, $dateMax = 0) { - if ($dateMax === 0) { + public function markReadFeed ($id, $idMax = 0) { + if ($idMax === 0) { $sql = 'UPDATE ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id ' . 'SET e.is_read = 1, f.cache_nbUnreads=0 ' . 'WHERE f.id=? AND e.is_read = 0'; @@ -413,8 +413,8 @@ class EntryDAO extends Model_pdo { $sql = 'UPDATE ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id ' . 'SET e.is_read = 1 ' - . 'WHERE f.id=? AND e.is_read = 0 AND e.date < ?'; - $values = array ($id, $dateMax); + . 'WHERE f.id=? AND e.is_read = 0 AND e.id <= ?'; + $values = array ($id, $idMax); $stm = $this->bd->prepare ($sql); if (!($stm && $stm->execute ($values))) { $info = $stm->errorInfo(); @@ -471,11 +471,11 @@ class EntryDAO extends Model_pdo { }*/ public function cleanOldEntries ($date_min) { - $sql = 'DELETE e.* FROM ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id WHERE e.date <= ? AND e.is_favorite = 0 AND f.keep_history = 0'; + $sql = 'DELETE e.* FROM ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id WHERE e.id <= ? AND e.is_favorite = 0 AND f.keep_history = 0'; $stm = $this->bd->prepare ($sql); $values = array ( - $date_min + $date_min . '000000' ); if ($stm && $stm->execute ($values)) { @@ -531,8 +531,8 @@ class EntryDAO extends Model_pdo { } elseif ($state === 'read') { $where .= ' AND is_read = 1'; } - if (!empty($limitFromId)) { //TODO: Consider using LPAD(e.date, 11) //CONCAT is for cases when many entries have the same date - $where .= ' AND CONCAT(e.date, e.id) ' . ($order === 'low_to_high' ? '<=' : '>=') . ' (SELECT CONCAT(s.date, s.id) FROM ' . $this->prefix . 'entry s WHERE s.id = "' . $limitFromId . '")'; + if (!empty($limitFromId)) { + $where .= ' AND e.id ' . ($order === 'low_to_high' ? '<=' : '>=') . $limitFromId; } if ($order === 'low_to_high') { @@ -543,7 +543,7 @@ class EntryDAO extends Model_pdo { $sql = 'SELECT e.* FROM ' . $this->prefix . 'entry e' . ' INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id' . $where - . ' ORDER BY e.date' . $order . ', e.id' . $order; + . ' ORDER BY e.id' . $order; if (empty($limitCount)) { $limitCount = 20000; //TODO: FIXME: Hack temporaire en attendant la recherche côté base-de-données @@ -571,7 +571,7 @@ class EntryDAO extends Model_pdo { } public function listLastGuidsByFeed($id, $n) { - $sql = 'SELECT guid FROM ' . $this->prefix . 'entry WHERE id_feed=? ORDER BY date DESC LIMIT ' . intval($n); + $sql = 'SELECT guid FROM ' . $this->prefix . 'entry WHERE id_feed=? ORDER BY id DESC LIMIT ' . intval($n); $stm = $this->bd->prepare ($sql); $values = array ($id); $stm->execute ($values); diff --git a/app/models/Feed.php b/app/models/Feed.php index 8927551d6..da1a029a8 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -256,16 +256,6 @@ class Feed extends Model { } } } - static function html_only_entity_decode($text) { - static $htmlEntitiesOnly = null; - if ($htmlEntitiesOnly === null) { - $htmlEntitiesOnly = array_flip(array_diff( - get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES, 'UTF-8'), //Decode HTML entities - get_html_translation_table(HTML_SPECIALCHARS, ENT_NOQUOTES, 'UTF-8') //Preserve XML entities - )); - } - return strtr($text, $htmlEntitiesOnly); - } private function loadEntries ($feed) { $entries = array (); diff --git a/app/models/RSSPaginator.php b/app/models/RSSPaginator.php index 86b4b5cac..60d2a06ac 100644 --- a/app/models/RSSPaginator.php +++ b/app/models/RSSPaginator.php @@ -23,6 +23,10 @@ class RSSPaginator { return $this->next; } + public function peek () { + return empty($this->items) ? null : $this->items[0]; + } + public function render ($view, $getteur) { $view = APP_PATH . '/views/helpers/'.$view; -- cgit v1.2.3