From 97c3c7575a586382ea87f8faa1e9e78afb64710a Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 10 Nov 2013 19:45:48 +0100 Subject: Suppression des warnings liés à filemtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ajout de "@" pour éviter les warnings, touch.txt sera créé un peu plus tard --- app/controllers/indexController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/controllers/indexController.php') diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index ee40ff9d2..2f86034ee 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -49,10 +49,10 @@ class indexController extends ActionController { Request::_param ('output', $output); } - View::appendScript (Url::display ('/scripts/shortcut.js?' . filemtime(PUBLIC_PATH . '/scripts/shortcut.js'))); + View::appendScript (Url::display ('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js'))); if ($output == 'global') { - View::appendScript (Url::display ('/scripts/global_view.js?' . filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); + View::appendScript (Url::display ('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); } } -- cgit v1.2.3 From 58cb842966f437a44f58644439f513b94f9dccac Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 12 Nov 2013 18:22:41 +0100 Subject: Suppression multiples requêtes count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suppression de plusieurs requêtes count inutiles (genre `$entryDAO->countNotRead()` avant un UPDATE), et suppression de l'affichage du nombre d'articles total. Corrige https://github.com/marienfressinaud/FreshRSS/issues/246 --- app/App_FrontController.php | 4 ---- app/controllers/indexController.php | 28 ++++++++++++++++------------ app/i18n/en.php | 2 +- app/i18n/fr.php | 2 +- app/layout/aside_flux.phtml | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) (limited to 'app/controllers/indexController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 5569d73a3..950956555 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -43,10 +43,6 @@ class App_FrontController extends FrontController { private function loadParamsView () { $this->conf = Session::param ('conf', new RSSConfiguration ()); View::_param ('conf', $this->conf); - - $entryDAO = new EntryDAO (); - View::_param ('nb_not_read', $entryDAO->countNotRead ()); - Session::_param ('language', $this->conf->language ()); } diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 2f86034ee..e99ae2e44 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -2,7 +2,6 @@ class indexController extends ActionController { private $get = false; - private $nb_not_read = 0; private $nb_not_read_cat = 0; public function indexAction () { @@ -56,19 +55,12 @@ class indexController extends ActionController { } } - $nb_not_read = $this->view->nb_not_read; - if($nb_not_read > 0) { - View::appendTitle (' (' . $nb_not_read . ')'); - } - View::prependTitle (' - '); - $entryDAO = new EntryDAO (); $feedDAO = new FeedDAO (); $catDAO = new CategoryDAO (); $this->view->cat_aside = $catDAO->listCategories (); $this->view->nb_favorites = $entryDAO->countUnreadReadFavorites (); - $this->view->nb_total = $entryDAO->count (); $this->view->currentName = ''; $this->view->get_c = ''; @@ -78,6 +70,12 @@ class indexController extends ActionController { $error = $this->checkAndProcessType ($type); // mise à jour des titres + $this->view->nb_not_read = HelperCategory::CountUnreads($this->view->cat_aside, 1); + if ($this->view->nb_not_read > 0) { + View::appendTitle (' (' . $this->view->nb_not_read . ')'); + } + View::prependTitle (' - '); + $this->view->rss_title = $this->view->currentName . ' - ' . $this->view->rss_title; View::prependTitle ( $this->view->currentName . @@ -166,8 +164,11 @@ class indexController extends ActionController { $this->view->get_c = $type['type']; return false; } elseif ($type['type'] == 'c') { - $catDAO = new CategoryDAO (); - $cat = $catDAO->searchById ($type['id']); + $cat = isset($this->view->cat_aside[$type['id']]) ? $this->view->cat_aside[$type['id']] : null; + if ($cat === null) { + $catDAO = new CategoryDAO (); + $cat = $catDAO->searchById ($type['id']); + } if ($cat) { $this->view->currentName = $cat->name (); $this->nb_not_read_cat = $cat->nbNotRead (); @@ -177,8 +178,11 @@ class indexController extends ActionController { return true; } } elseif ($type['type'] == 'f') { - $feedDAO = new FeedDAO (); - $feed = $feedDAO->searchById ($type['id']); + $feed = HelperCategory::findFeed($this->view->cat_aside, $type['id']); + if (empty($feed)) { + $feedDAO = new FeedDAO (); + $feed = $feedDAO->searchById ($type['id']); + } if ($feed) { $this->view->currentName = $feed->name (); $this->nb_not_read_cat = $feed->nbNotRead (); diff --git a/app/i18n/en.php b/app/i18n/en.php index 2f9232160..0a9ca2cb0 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -19,7 +19,7 @@ return array ( 'import_export_opml' => 'Import / export (OPML)', 'subscription_management' => 'Subscriptions management', - 'all_feeds' => 'Main stream (%d)', + 'all_feeds' => 'Main stream', 'favorite_feeds' => 'Favourites (%d)', 'not_read' => '%d unread', 'not_reads' => '%d unread', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 922bda134..063c0cad7 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -19,7 +19,7 @@ return array ( 'import_export_opml' => 'Importer / exporter (OPML)', 'subscription_management' => 'Gestion des abonnements', - 'all_feeds' => 'Flux principal (%d)', + 'all_feeds' => 'Flux principal', 'favorite_feeds' => 'Favoris (%d)', 'not_read' => '%d non lu', 'not_reads' => '%d non lus', diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtml index aa1624f69..511bb4564 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -15,7 +15,7 @@ -- cgit v1.2.3 From 6fe1e1bad0c0164e187ce4c560c2f35bafdff9a5 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 13 Nov 2013 23:34:30 +0100 Subject: Ajout d'un bouton pour effacer les logs https://github.com/marienfressinaud/FreshRSS/issues/242 --- app/controllers/indexController.php | 4 ++++ app/i18n/en.php | 1 + app/i18n/fr.php | 1 + app/views/index/logs.phtml | 4 ++++ 4 files changed, 10 insertions(+) (limited to 'app/controllers/indexController.php') diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index e99ae2e44..7b5dbd264 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -211,6 +211,10 @@ class indexController extends ActionController { View::prependTitle (Translate::t ('logs') . ' - '); + if (Request::isPost ()) { + file_put_contents(LOG_PATH . '/application.log', ''); + } + $logs = array(); try { $logDAO = new LogDAO (); diff --git a/app/i18n/en.php b/app/i18n/en.php index 0a9ca2cb0..6147b268a 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -214,6 +214,7 @@ return array ( 'logs' => 'Logs', 'logs_empty' => 'Log file is empty', + 'clear_logs' => 'Clear the logs', 'forbidden_access' => 'Forbidden access', 'forbidden_access_description' => 'Access is password protected, please to read your feeds.', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 063c0cad7..e260cdf50 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -214,6 +214,7 @@ return array ( 'logs' => 'Logs', 'logs_empty' => 'Les logs sont vides', + 'clear_logs' => 'Effacer les logs', 'forbidden_access' => 'Accès interdit', 'forbidden_access_description' => 'L’accès est protégé par un mot de passe, veuillez pour accéder aux flux.', diff --git a/app/views/index/logs.phtml b/app/views/index/logs.phtml index 09f0c4ecd..71a55a1b7 100644 --- a/app/views/index/logs.phtml +++ b/app/views/index/logs.phtml @@ -2,6 +2,10 @@

+

+ + +

logsPaginator->items (); ?> -- cgit v1.2.3 From 32306a78d2e53bbbc864f3eabda9a2f1a3dd2322 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 16 Nov 2013 21:03:25 +0100 Subject: SQL : grosse mise à jour avec mise en cache du nombre d'articles lus/non-lus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Mise en cache du nombre d'articles lus et non-lus par flux, via `f.cache_nbEntries, f.cache_nbUnreads` pour de biens meilleures performances * Implémente https://github.com/marienfressinaud/FreshRSS/issues/268 * Révision de la plupart des requêtes de modification en conséquence * En cas d'affichage `not_read`, évite de faire une requête si on sait déjà qu'il n'y a pas d'article non lu et fait directement un affichage `all`. * Appelle `cleanOldEntries` seulement une fois de temps en temps aléatoirement (1 fois sur 30 actuellement) pour économiser les ressources, et avant les insertions pour plus de robustesse. * Utilisation des transactions lors de mises à jour multiples et liées * Lors de requêtes de modifications, retourne le nombre de lignes impactées plutôt qu'un booléen en cas de succès * Suppression de code oublié relatif à is_public qui n'est plus utilisé --- app/controllers/entryController.php | 14 +-- app/controllers/feedController.php | 22 +++- app/controllers/indexController.php | 27 ++++- app/models/Category.php | 11 +- app/models/EntriesGetter.php | 8 -- app/models/Entry.php | 228 ++++++++++++++++++++++++++++-------- app/models/Feed.php | 84 +++++++------ lib/minz/dao/Model_pdo.php | 10 ++ public/install.php | 24 ++-- 9 files changed, 294 insertions(+), 134 deletions(-) (limited to 'app/controllers/indexController.php') diff --git a/app/controllers/entryController.php b/app/controllers/entryController.php index 1ba9cc3cd..4d2d92c1b 100755 --- a/app/controllers/entryController.php +++ b/app/controllers/entryController.php @@ -43,28 +43,27 @@ class entryController extends ActionController { $entryDAO = new EntryDAO (); if ($id == false) { if (!$get) { - $entryDAO->markReadEntries ($is_read, $dateMax); + $entryDAO->markReadEntries ($dateMax); } else { $typeGet = $get[0]; $get = substr ($get, 2); if ($typeGet == 'c') { - $entryDAO->markReadCat ($get, $is_read, $dateMax); + $entryDAO->markReadCat ($get, $dateMax); $this->params = array ('get' => $nextGet); } elseif ($typeGet == 'f') { - $entryDAO->markReadFeed ($get, $is_read, $dateMax); + $entryDAO->markReadFeed ($get, $dateMax); $this->params = array ('get' => $nextGet); } } - // notif $notif = array ( 'type' => 'good', 'content' => Translate::t ('feeds_marked_read') ); Session::_param ('notification', $notif); } else { - $entryDAO->updateEntry ($id, array ('is_read' => $is_read)); + $entryDAO->markRead ($id, $is_read); } } @@ -74,10 +73,7 @@ class entryController extends ActionController { $id = Request::param ('id'); if ($id) { $entryDAO = new EntryDAO (); - $values = array ( - 'is_favorite' => (bool)(Request::param ('is_favorite')), - ); - $entryDAO->updateEntry ($id, $values); + $entryDAO->markFavorite ($id, Request::param ('is_favorite')); } } diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php index 76fca8828..0ba82631c 100755 --- a/app/controllers/feedController.php +++ b/app/controllers/feedController.php @@ -33,6 +33,7 @@ class feedController extends ActionController { $pass = Request::param ('password'); $params = array (); + $transactionStarted = false; try { $feed = new Feed ($url); $feed->_category ($cat); @@ -79,6 +80,8 @@ class feedController extends ActionController { $nb_month_old = $this->view->conf->oldEntries (); $date_min = time () - (60 * 60 * 24 * 30 * $nb_month_old); + $transactionStarted = true; + $feedDAO->beginTransaction (); // on ajoute les articles en masse sans vérification foreach ($entries as $entry) { if ($entry->date (true) >= $date_min || @@ -87,6 +90,9 @@ class feedController extends ActionController { $entryDAO->addEntry ($values); } } + $feedDAO->updateLastUpdate ($feed->id ()); + $feedDAO->commit (); + $transactionStarted = false; // ok, ajout terminé $notif = array ( @@ -121,6 +127,9 @@ class feedController extends ActionController { ); Session::_param ('notification', $notif); } + if ($transactionStarted) { + $feedDAO->rollBack (); + } Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => $params), true); } @@ -149,6 +158,13 @@ class feedController extends ActionController { // on calcule la date des articles les plus anciens qu'on accepte $nb_month_old = $this->view->conf->oldEntries (); $date_min = time () - (60 * 60 * 24 * 30 * $nb_month_old); + if (rand(0, 30) === 1) { + Minz_Log::record ('CleanOldEntries', Minz_Log::NOTICE); //TODO: Remove + if ($entryDAO->cleanOldEntries ($date_min) > 0) { + Minz_Log::record ('UpdateCachedValues', Minz_Log::NOTICE); //TODO: Remove + $feedDAO->updateCachedValues (); + } + } $i = 0; $flux_update = 0; @@ -165,6 +181,7 @@ class feedController extends ActionController { // car demanderait plus de ressources // La BDD refusera l'ajout de son côté car l'id doit être // unique + $feedDAO->beginTransaction (); foreach ($entries as $entry) { if ((!isset ($existingIds[$entry->id ()])) && ($entry->date (true) >= $date_min || @@ -176,10 +193,11 @@ class feedController extends ActionController { // on indique que le flux vient d'être mis à jour en BDD $feedDAO->updateLastUpdate ($feed->id ()); + $feedDAO->commit (); $flux_update++; } catch (FeedException $e) { Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - $feedDAO->isInError ($feed->id ()); + $feedDAO->updateLastUpdate ($feed->id (), 1); } // On arrête à 10 flux pour ne pas surcharger le serveur @@ -190,8 +208,6 @@ class feedController extends ActionController { } } - $entryDAO->cleanOldEntries ($nb_month_old); - $url = array (); if ($flux_update === 1) { // on a mis un seul flux à jour diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 7b5dbd264..10c29bc7b 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -90,6 +90,30 @@ class indexController extends ActionController { $nb = Request::param ('nb', $this->view->conf->postsPerPage ()); $first = Request::param ('next', ''); + if ($state === 'not_read') { //Any unread article in this category at all? + switch ($type['type']) { + case 'all': + $hasUnread = $this->view->nb_not_read > 0; + break; + case 'favoris': + $hasUnread = $this->view->nb_favorites['unread'] > 0; + break; + case 'c': + $hasUnread = (!isset($this->view->cat_aside[$type['id']])) || ($this->view->cat_aside[$type['id']]->nbNotRead() > 0); + break; + case 'f': + $myFeed = HelperCategory::findFeed($this->view->cat_aside, $type['id']); + $hasUnread = ($myFeed === null) || ($myFeed->nbNotRead() > 0); + break; + default: + $hasUnread = true; + break; + } + if (!$hasUnread) { + $this->view->state = $state = 'all'; + } + } + try { // EntriesGetter permet de déporter la complexité du filtrage $getter = new EntriesGetter ($type, $state, $filter, $order, $nb, $first); @@ -98,7 +122,8 @@ class indexController extends ActionController { // Si on a récupéré aucun article "non lus" // on essaye de récupérer tous les articles - if ($state == 'not_read' && $entries->isEmpty ()) { + if ($state === 'not_read' && $entries->isEmpty ()) { //TODO: Remove in v0.8 + Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::NOTICE); //TODO: Consider adding a Minz_Log::DEBUG level $this->view->state = 'all'; $getter->_state ('all'); $getter->execute (); diff --git a/app/models/Category.php b/app/models/Category.php index 9b36b3bcc..6e61b5a0e 100755 --- a/app/models/Category.php +++ b/app/models/Category.php @@ -100,7 +100,7 @@ class CategoryDAO extends Model_pdo { ); if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); @@ -119,7 +119,7 @@ class CategoryDAO extends Model_pdo { ); if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); @@ -134,7 +134,7 @@ class CategoryDAO extends Model_pdo { $values = array ($id); if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); @@ -179,12 +179,9 @@ class CategoryDAO extends Model_pdo { if ($prePopulateFeeds) { $sql = 'SELECT c.id AS c_id, c.name AS c_name, ' . ($details ? 'c.color AS c_color, ' : '') - . 'COUNT(CASE WHEN e.is_read = 0 THEN 1 END) AS nbNotRead, ' - . 'COUNT(e.id) AS nbEntries, ' - . ($details ? 'f.* ' : 'f.id, f.name, f.website, f.priority, f.error ') + . ($details ? 'f.* ' : 'f.id, f.name, f.website, f.priority, f.error, f.cache_nbEntries, f.cache_nbUnreads ') . 'FROM ' . $this->prefix . 'category c ' . 'LEFT OUTER JOIN ' . $this->prefix . 'feed f ON f.category = c.id ' - . 'LEFT OUTER JOIN ' . $this->prefix . 'entry e ON e.id_feed = f.id ' . 'GROUP BY f.id ' . 'ORDER BY c.name, f.name'; $stm = $this->bd->prepare ($sql); diff --git a/app/models/EntriesGetter.php b/app/models/EntriesGetter.php index 803aad732..ce026f252 100644 --- a/app/models/EntriesGetter.php +++ b/app/models/EntriesGetter.php @@ -117,14 +117,6 @@ class EntriesGetter { $sqlLimit ); break; - case 'public': - list ($this->entries, $this->next) = $entryDAO->listPublic ( - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; case 'c': list ($this->entries, $this->next) = $entryDAO->listByCategory ( $this->type['id'], diff --git a/app/models/Entry.php b/app/models/Entry.php index c6715a431..8b817cc14 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -213,17 +213,17 @@ class EntryDAO extends Model_pdo { ); if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); if ((int)($info[0] / 1000) !== 23) { //Filter out "SQLSTATE Class code 23: Constraint Violation" because of expected duplicate entries - Minz_Log::record ('SQL error ' . $info[0] . ': ' . $info[1] . ' ' . $info[2], Minz_Log::NOTICE); //TODO: Consider adding a Minz_Log::DEBUG level + Minz_Log::record ('SQL error ' . $info[0] . ': ' . $info[1] . ' ' . $info[2], Minz_Log::ERROR); } return false; } } - public function updateEntry ($id, $valuesTmp) { + /*public function updateEntry ($id, $valuesTmp) { if (isset ($valuesTmp['content'])) { $valuesTmp['content'] = base64_encode (gzdeflate (serialize ($valuesTmp['content']))); } @@ -243,73 +243,201 @@ class EntryDAO extends Model_pdo { $values[] = $id; if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); return false; } - } - - public function markReadEntries ($read, $dateMax = 0) { - $sql = 'UPDATE ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id SET is_read = ? WHERE priority > 0'; - - $values = array ($read); - if ($dateMax > 0) { - $sql .= ' AND date < ?'; - $values[] = $dateMax; - } - + }*/ + public function markFavorite ($id, $is_favorite = true) { + $sql = 'UPDATE ' . $this->prefix . 'entry e ' + . 'SET e.is_favorite = ? ' + . 'WHERE e.id=?'; + $values = array ($is_favorite ? 1 : 0, $id); $stm = $this->bd->prepare ($sql); if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); return false; } } - public function markReadCat ($id, $read, $dateMax = 0) { - $sql = 'UPDATE ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id SET is_read = ? WHERE category = ?'; - - $values = array ($read, $id); - if ($dateMax > 0) { - $sql .= ' AND date < ?'; - $values[] = $dateMax; - } - + public function markRead ($id, $is_read = true) { + $sql = 'UPDATE ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id ' + . 'SET e.is_read = ?,' + . 'f.cache_nbUnreads=f.cache_nbUnreads' . ($is_read ? '-' : '+') . '1 ' + . 'WHERE e.id=?'; + $values = array ($is_read ? 1 : 0, $id); $stm = $this->bd->prepare ($sql); if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); return false; } } - public function markReadFeed ($id, $read, $dateMax = 0) { - $sql = 'UPDATE ' . $this->prefix . 'entry SET is_read = ? WHERE id_feed = ?'; + public function markReadEntries ($dateMax = 0) { + if ($dateMax === 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'; + $stm = $this->bd->prepare ($sql); + if ($stm && $stm->execute ()) { + return $stm->rowCount(); + } else { + $info = $stm->errorInfo(); + Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + return false; + } + } else { + $this->bd->beginTransaction (); + + $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); + $stm = $this->bd->prepare ($sql); + if (!($stm && $stm->execute ($values))) { + $info = $stm->errorInfo(); + Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } + $affected = $stm->rowCount(); + + if ($affected > 0) { + $sql = 'UPDATE freshrss_feed f ' + . 'LEFT OUTER JOIN (' + . 'SELECT e.id_feed, ' + . 'COUNT(*) AS nbUnreads ' + . 'FROM freshrss_entry e ' + . 'WHERE e.is_read = 0 ' + . 'GROUP BY e.id_feed' + . ') x ON x.id_feed=f.id ' + . 'SET f.cache_nbUnreads=COALESCE(x.nbUnreads, 0)'; + $stm = $this->bd->prepare ($sql); + if (!($stm && $stm->execute ())) { + $info = $stm->errorInfo(); + Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } + } - $values = array ($read, $id); - if ($dateMax > 0) { - $sql .= ' AND date < ?'; - $values[] = $dateMax; + $this->bd->commit (); + return $affected; } + } + public function markReadCat ($id, $dateMax = 0) { + if ($dateMax === 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'; + $values = array ($id); + $stm = $this->bd->prepare ($sql); + if ($stm && $stm->execute ($values)) { + return $stm->rowCount(); + } else { + $info = $stm->errorInfo(); + Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + return false; + } + } else { + $this->bd->beginTransaction (); + + $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); + $stm = $this->bd->prepare ($sql); + if (!($stm && $stm->execute ($values))) { + $info = $stm->errorInfo(); + Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } + $affected = $stm->rowCount(); + + if ($affected > 0) { + $sql = 'UPDATE freshrss_feed f ' + . 'LEFT OUTER JOIN (' + . 'SELECT e.id_feed, ' + . 'COUNT(*) AS nbUnreads ' + . 'FROM freshrss_entry e ' + . 'WHERE e.is_read = 0 ' + . 'GROUP BY e.id_feed' + . ') x ON x.id_feed=f.id ' + . 'SET f.cache_nbUnreads=COALESCE(x.nbUnreads, 0) ' + . 'WHERE f.category = ?'; + $values = array ($id); + $stm = $this->bd->prepare ($sql); + if (!($stm && $stm->execute ($values))) { + $info = $stm->errorInfo(); + Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } + } - $stm = $this->bd->prepare ($sql); - - if ($stm && $stm->execute ($values)) { - return true; + $this->bd->commit (); + return $affected; + } + } + public function markReadFeed ($id, $dateMax = 0) { + if ($dateMax === 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'; + $values = array ($id); + $stm = $this->bd->prepare ($sql); + if ($stm && $stm->execute ($values)) { + return $stm->rowCount(); + } else { + $info = $stm->errorInfo(); + Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + return false; + } } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; + $this->bd->beginTransaction (); + + $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); + $stm = $this->bd->prepare ($sql); + if (!($stm && $stm->execute ($values))) { + $info = $stm->errorInfo(); + Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } + $affected = $stm->rowCount(); + + if ($affected > 0) { + $sql = 'UPDATE ' . $this->prefix . 'feed f ' + . 'SET f.cache_nbUnreads=f.cache_nbUnreads-' . $affected + . ' WHERE f.id=?'; + $values = array ($id); + $stm = $this->bd->prepare ($sql); + if (!($stm && $stm->execute ($values))) { + $info = $stm->errorInfo(); + Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } + } + + $this->bd->commit (); + return $affected; } } - public function updateEntries ($valuesTmp) { + /*public function updateEntries ($valuesTmp) { if (isset ($valuesTmp['content'])) { $valuesTmp['content'] = base64_encode (gzdeflate (serialize ($valuesTmp['content']))); } @@ -328,25 +456,24 @@ class EntryDAO extends Model_pdo { } if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); return false; } - } + }*/ - public function cleanOldEntries ($nb_month) { - $date = 60 * 60 * 24 * 30 * $nb_month; + 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'; $stm = $this->bd->prepare ($sql); $values = array ( - time () - $date + $date_min ); if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); @@ -393,16 +520,16 @@ class EntryDAO extends Model_pdo { } private function listWhere ($where, $state, $order, $limitFromId = '', $limitCount = '', $values = array ()) { - if ($state == 'not_read') { + if ($state === 'not_read') { $where .= ' AND is_read = 0'; - } elseif ($state == 'read') { + } 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 ($order == 'low_to_high') { + if ($order === 'low_to_high') { $order = ' DESC'; } else { $order = ''; @@ -430,9 +557,6 @@ class EntryDAO extends Model_pdo { public function listFavorites ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { return $this->listWhere (' WHERE is_favorite = 1', $state, $order, $limitFromId, $limitCount); } - public function listPublic ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere (' WHERE is_public = 1', $state, $order, $limitFromId, $limitCount); - } public function listByCategory ($cat, $state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { return $this->listWhere (' WHERE category = ?', $state, $order, $limitFromId, $limitCount, array ($cat)); } diff --git a/app/models/Feed.php b/app/models/Feed.php index 407614f9f..ae3a9af83 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -337,7 +337,7 @@ class FeedDAO extends Model_pdo { ); if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); @@ -365,7 +365,7 @@ class FeedDAO extends Model_pdo { $values[] = $id; if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); @@ -373,34 +373,23 @@ class FeedDAO extends Model_pdo { } } - public function updateLastUpdate ($id) { - $sql = 'UPDATE ' . $this->prefix . 'feed SET lastUpdate=?, error=0 WHERE id=?'; - $stm = $this->bd->prepare ($sql); - - $values = array ( - time (), - $id - ); + public function updateLastUpdate ($id, $inError = 0) { + $sql = 'UPDATE ' . $this->prefix . 'feed f ' //2 sub-requests with FOREIGN KEY(e.id_feed), INDEX(e.is_read) faster than 1 request with GROUP BY or CASE + . 'SET f.cache_nbEntries=(SELECT COUNT(e1.id) FROM ' . $this->prefix . 'entry e1 WHERE e1.id_feed=f.id),' + . 'f.cache_nbUnreads=(SELECT COUNT(e2.id) FROM ' . $this->prefix . 'entry e2 WHERE e2.id_feed=f.id AND e2.is_read=0),' + . 'lastUpdate=?, error=? ' + . 'WHERE f.id=?'; - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function isInError ($id) { - $sql = 'UPDATE ' . $this->prefix . 'feed SET error=1 WHERE id=?'; $stm = $this->bd->prepare ($sql); $values = array ( - $id + time (), + $inError, + $id, ); if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); @@ -424,7 +413,7 @@ class FeedDAO extends Model_pdo { ); if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); @@ -439,7 +428,7 @@ class FeedDAO extends Model_pdo { $values = array ($id); if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); @@ -453,7 +442,7 @@ class FeedDAO extends Model_pdo { $values = array ($id); if ($stm && $stm->execute ($values)) { - return true; + return $stm->rowCount(); } else { $info = $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); @@ -521,15 +510,6 @@ class FeedDAO extends Model_pdo { return HelperFeed::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC)); } - public function count () { //Is this used? - $sql = 'SELECT COUNT(*) AS count FROM ' . $this->prefix . 'feed'; - $stm = $this->bd->prepare ($sql); - $stm->execute (); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - - return $res[0]['count']; - } - public function countEntries ($id) { $sql = 'SELECT COUNT(*) AS count FROM ' . $this->prefix . 'entry WHERE id_feed=?'; $stm = $this->bd->prepare ($sql); @@ -539,8 +519,8 @@ class FeedDAO extends Model_pdo { return $res[0]['count']; } - public function countNotRead ($id) { //Is this used? - $sql = 'SELECT COUNT(*) AS count FROM ' . $this->prefix . 'entry WHERE is_read=0 AND id_feed=?'; + public function countNotRead ($id) { + $sql = 'SELECT COUNT(*) AS count FROM ' . $this->prefix . 'entry WHERE id_feed=? AND is_read=0'; $stm = $this->bd->prepare ($sql); $values = array ($id); $stm->execute ($values); @@ -548,6 +528,28 @@ class FeedDAO extends Model_pdo { return $res[0]['count']; } + public function updateCachedValues () { //For one single feed, call updateLastUpdate($id) + $sql = 'UPDATE freshrss_feed f ' + . 'INNER JOIN (' + . 'SELECT e.id_feed, ' + . 'COUNT(CASE WHEN e.is_read = 0 THEN 1 END) AS nbUnreads, ' + . 'COUNT(e.id) AS nbEntries ' + . 'FROM freshrss_entry e ' + . 'GROUP BY e.id_feed' + . ') x ON x.id_feed=f.id ' + . 'SET f.cache_nbEntries=x.nbEntries, f.cache_nbUnreads=x.nbUnreads'; + $stm = $this->bd->prepare ($sql); + + $values = array ($feed_id); + + if ($stm && $stm->execute ($values)) { + return $stm->rowCount(); + } else { + $info = $stm->errorInfo(); + Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + return false; + } + } } class HelperFeed { @@ -577,12 +579,8 @@ class HelperFeed { $myFeed->_httpAuth (isset($dao['httpAuth']) ? base64_decode ($dao['httpAuth']) : ''); $myFeed->_error ($dao['error']); $myFeed->_keepHistory (isset($dao['keep_history']) ? $dao['keep_history'] : ''); - if (isset ($dao['nbNotRead'])) { - $myFeed->_nbNotRead ($dao['nbNotRead']); - } - if (isset ($dao['nbEntries'])) { - $myFeed->_nbEntries ($dao['nbEntries']); - } + $myFeed->_nbNotRead ($dao['cache_nbUnreads']); + $myFeed->_nbEntries ($dao['cache_nbEntries']); if (isset ($dao['id'])) { $myFeed->_id ($dao['id']); } diff --git a/lib/minz/dao/Model_pdo.php b/lib/minz/dao/Model_pdo.php index a91a4fa00..dd75153be 100755 --- a/lib/minz/dao/Model_pdo.php +++ b/lib/minz/dao/Model_pdo.php @@ -71,6 +71,16 @@ class Model_pdo { ); } } + + public function beginTransaction() { + $this->bd->beginTransaction(); + } + public function commit() { + $this->bd->commit(); + } + public function rollBack() { + $this->bd->rollBack(); + } } class FreshPDO extends PDO { diff --git a/public/install.php b/public/install.php index 457605224..47856b6a7 100644 --- a/public/install.php +++ b/public/install.php @@ -15,7 +15,7 @@ define ('SQL_REQ_CAT', 'CREATE TABLE IF NOT EXISTS `%scategory` ( `name` varchar(255) NOT NULL, `color` char(7) NOT NULL, PRIMARY KEY (`id`), - INDEX (`name`) + INDEX (`name`) //v0.7 );'); define ('SQL_REQ_FEED', 'CREATE TABLE IF NOT EXISTS `%sfeed` ( @@ -26,16 +26,18 @@ define ('SQL_REQ_FEED', 'CREATE TABLE IF NOT EXISTS `%sfeed` ( `website` varchar(255) NOT NULL, `description` text NOT NULL, `lastUpdate` int(11) NOT NULL, - `priority` tinyint(2) NOT NULL DEFAULT \'10\', + `priority` tinyint(2) NOT NULL DEFAULT 10, `pathEntries` varchar(511) DEFAULT NULL, `httpAuth` varchar(511) DEFAULT NULL, - `error` boolean NOT NULL DEFAULT \'0\', - `keep_history` boolean NOT NULL DEFAULT \'0\', + `error` boolean NOT NULL DEFAULT 0, + `keep_history` boolean NOT NULL DEFAULT 0, + `cache_nbEntries` int NOT NULL DEFAULT 0, //v0.7 + `cache_nbUnreads` int NOT NULL DEFAULT 0, //v0.7 PRIMARY KEY (`id`), FOREIGN KEY (`category`) REFERENCES %scategory(id) ON DELETE SET NULL ON UPDATE CASCADE, - INDEX (`name`), - INDEX (`priority`), - INDEX (`keep_history`) + INDEX (`name`), //v0.7 + INDEX (`priority`), //v0.7 + INDEX (`keep_history`) //v0.7 );'); define ('SQL_REQ_ENTRY', 'CREATE TABLE IF NOT EXISTS `%sentry` ( @@ -46,14 +48,14 @@ define ('SQL_REQ_ENTRY', 'CREATE TABLE IF NOT EXISTS `%sentry` ( `content` text NOT NULL, `link` varchar(1023) NOT NULL, `date` int(11) NOT NULL, - `is_read` boolean NOT NULL DEFAULT \'0\', - `is_favorite` boolean NOT NULL DEFAULT \'0\', + `is_read` boolean NOT NULL DEFAULT 0, + `is_favorite` boolean NOT NULL DEFAULT 0, `id_feed` char(6) NOT NULL, `tags` varchar(1023) NOT NULL, PRIMARY KEY (`id`), FOREIGN KEY (`id_feed`) REFERENCES %sfeed(id) ON DELETE CASCADE ON UPDATE CASCADE, - INDEX (`is_favorite`), - INDEX (`is_read`) + INDEX (`is_favorite`), //v0.7 + INDEX (`is_read`) //v0.7 );'); -- cgit v1.2.3 From 4a2b17d54ab3714c4f567a43a7a2e701cd9a7b49 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 16 Nov 2013 22:41:03 +0100 Subject: Minz : nouveau Minz_Log::DEBUG Nouveau niveau Minz_Log::DEBUG pour plus de finesse dans les messages --- app/controllers/configureController.php | 2 +- app/controllers/feedController.php | 12 ++++++------ app/controllers/indexController.php | 4 ++-- lib/minz/Minz_Log.php | 23 ++++++++++++++--------- public/index.php | 5 +++-- public/themes/default/freshrss.css | 4 ++++ public/themes/flat-design/freshrss.css | 12 ++++++++---- 7 files changed, 38 insertions(+), 24 deletions(-) (limited to 'app/controllers/indexController.php') diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php index 815f3f5f4..2856bb89f 100755 --- a/app/controllers/configureController.php +++ b/app/controllers/configureController.php @@ -302,7 +302,7 @@ class configureController extends ActionController { Request::_param ('feeds', $feeds); Request::forward (array ('c' => 'feed', 'a' => 'massiveImport')); } catch (OpmlException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); + Minz_Log::record ($e->getMessage (), Minz_Log::WARNING); $notif = array ( 'type' => 'bad', diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php index 0ba82631c..e54a2ac12 100755 --- a/app/controllers/feedController.php +++ b/app/controllers/feedController.php @@ -105,14 +105,14 @@ class feedController extends ActionController { $params['id'] = $feed->id (); } } catch (BadUrlException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); + Minz_Log::record ($e->getMessage (), Minz_Log::WARNING); $notif = array ( 'type' => 'bad', 'content' => Translate::t ('invalid_url', $url) ); Session::_param ('notification', $notif); } catch (FeedException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); + Minz_Log::record ($e->getMessage (), Minz_Log::WARNING); $notif = array ( 'type' => 'bad', 'content' => Translate::t ('internal_problem_feed') @@ -159,9 +159,9 @@ class feedController extends ActionController { $nb_month_old = $this->view->conf->oldEntries (); $date_min = time () - (60 * 60 * 24 * 30 * $nb_month_old); if (rand(0, 30) === 1) { - Minz_Log::record ('CleanOldEntries', Minz_Log::NOTICE); //TODO: Remove + Minz_Log::record ('CleanOldEntries', Minz_Log::DEBUG); if ($entryDAO->cleanOldEntries ($date_min) > 0) { - Minz_Log::record ('UpdateCachedValues', Minz_Log::NOTICE); //TODO: Remove + Minz_Log::record ('UpdateCachedValues', Minz_Log::DEBUG); $feedDAO->updateCachedValues (); } } @@ -196,7 +196,7 @@ class feedController extends ActionController { $feedDAO->commit (); $flux_update++; } catch (FeedException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); + Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); $feedDAO->updateLastUpdate ($feed->id (), 1); } @@ -298,7 +298,7 @@ class feedController extends ActionController { } } catch (FeedException $e) { $error = true; - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); + Minz_Log::record ($e->getMessage (), Minz_Log::WARNING); } } diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 10c29bc7b..224d6fb9e 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -123,7 +123,7 @@ class indexController extends ActionController { // Si on a récupéré aucun article "non lus" // on essaye de récupérer tous les articles if ($state === 'not_read' && $entries->isEmpty ()) { //TODO: Remove in v0.8 - Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::NOTICE); //TODO: Consider adding a Minz_Log::DEBUG level + Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG); $this->view->state = 'all'; $getter->_state ('all'); $getter->execute (); @@ -131,7 +131,7 @@ class indexController extends ActionController { } $this->view->entryPaginator = $entries; - } catch(EntriesGetterException $e) { + } catch (EntriesGetterException $e) { Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); Error::error ( 404, diff --git a/lib/minz/Minz_Log.php b/lib/minz/Minz_Log.php index 153870435..e66cc040b 100644 --- a/lib/minz/Minz_Log.php +++ b/lib/minz/Minz_Log.php @@ -12,11 +12,13 @@ class Minz_Log { * Les différents niveau de log * ERROR erreurs bloquantes de l'application * WARNING erreurs pouvant géner le bon fonctionnement, mais non bloquantes - * NOTICE messages d'informations, affichés pour le déboggage + * NOTICE erreurs mineures ou messages d'informations + * DEBUG Informations affichées pour le déboggage */ - const ERROR = 0; - const WARNING = 10; - const NOTICE = 20; + const ERROR = 2; + const WARNING = 4; + const NOTICE = 8; + const DEBUG = 16; /** * Enregistre un message dans un fichier de log spécifique @@ -31,9 +33,9 @@ class Minz_Log { public static function record ($information, $level, $file_name = null) { $env = Configuration::environment (); - if (! ($env == Configuration::SILENT - || ($env == Configuration::PRODUCTION - && ($level == Minz_Log::WARNING || $level == Minz_Log::NOTICE)))) { + if (! ($env === Configuration::SILENT + || ($env === Configuration::PRODUCTION + && ($level <= Minz_Log::NOTICE)))) { if (is_null ($file_name)) { $file_name = LOG_PATH . '/application.log'; } @@ -48,6 +50,9 @@ class Minz_Log { case Minz_Log::NOTICE : $level_label = 'notice'; break; + case Minz_Log::DEBUG : + $level_label = 'debug'; + break; default : $level_label = 'unknown'; } @@ -83,7 +88,7 @@ class Minz_Log { $msg_get = str_replace("\n", '', '$_GET content : ' . print_r($_GET, true)); $msg_post = str_replace("\n", '', '$_POST content : ' . print_r($_POST, true)); - self::record($msg_get, Minz_Log::NOTICE, $file_name); - self::record($msg_post, Minz_Log::NOTICE, $file_name); + self::record($msg_get, Minz_Log::DEBUG, $file_name); + self::record($msg_post, Minz_Log::DEBUG, $file_name); } } diff --git a/public/index.php b/public/index.php index dc6da259d..1a1651707 100755 --- a/public/index.php +++ b/public/index.php @@ -54,8 +54,9 @@ if (file_exists (PUBLIC_PATH . '/install.php')) { $front_controller = new App_FrontController (); $front_controller->init (); $front_controller->run (); - } catch (PDOConnectionException $e) { + } catch (Exception $e) { + echo '### Fatal error! ###
', "\n"; Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - print '### Application problem ###
'."\n".'See logs files'; + echo 'See logs files.'; } } diff --git a/public/themes/default/freshrss.css b/public/themes/default/freshrss.css index 81ff6d196..c8231f93d 100644 --- a/public/themes/default/freshrss.css +++ b/public/themes/default/freshrss.css @@ -677,6 +677,10 @@ background: #f4f4f4; color: #aaa; } + .log.debug { + background: #111; + color: #eee; + } .form-group table { border-collapse:collapse; diff --git a/public/themes/flat-design/freshrss.css b/public/themes/flat-design/freshrss.css index 498a02c1e..ef59abb4d 100644 --- a/public/themes/flat-design/freshrss.css +++ b/public/themes/flat-design/freshrss.css @@ -658,21 +658,25 @@ body { color: #666; font-size: 90%; } - .log .date { + .log>.date { margin: 0 10px 0 0; padding: 5px 10px; border-radius: 20px; } - .log.error .date { + .log.error>.date { background: #e74c3c; color: #fff; } - .log.warning .date { + .log.warning>.date { background: #f39c12; } - .log.notice .date { + .log.notice>.date { background: #ecf0f1; } + .log.debug>.date { + background: #111; + color: #eee; + } .form-group table { border-collapse:collapse; -- cgit v1.2.3 From 9c5c023e36a24b58baeab108012cd9eb42ccda60 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 17 Nov 2013 02:56:30 +0100 Subject: Réorganisation des fichiers utilisateur MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implémente https://github.com/marienfressinaud/FreshRSS/issues/248 --- README.md | 2 +- actualize_script.php | 2 +- app/configuration/.gitignore | 1 - app/controllers/entryController.php | 2 +- app/controllers/indexController.php | 4 +-- app/i18n/en.php | 2 +- app/i18n/fr.php | 2 +- app/layout/layout.phtml | 2 +- app/models/Feed.php | 2 +- app/models/RSSConfiguration.php | 2 +- cache/.gitignore | 1 - constants.php | 13 ++++++---- data/.gitignore | 6 +++++ lib/lib_rss.php | 6 ++--- lib/minz/Configuration.php | 10 ++++---- lib/minz/dao/Model_pdo.php | 6 ++--- log/.gitignore | 1 - public/data/.gitignore | 4 --- public/data/grey.gif | Bin 56 -> 0 bytes public/index.php | 8 +++--- public/install.php | 47 ++++++++++++++++++------------------ public/themes/icons/grey.gif | Bin 0 -> 56 bytes 22 files changed, 61 insertions(+), 62 deletions(-) delete mode 100644 app/configuration/.gitignore delete mode 100644 cache/.gitignore create mode 100644 data/.gitignore delete mode 100644 log/.gitignore delete mode 100644 public/data/.gitignore delete mode 100644 public/data/grey.gif create mode 100644 public/themes/icons/grey.gif (limited to 'app/controllers/indexController.php') diff --git a/README.md b/README.md index 00df693e6..fb0b9e61e 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Privilégiez pour cela des demandes sur GitHub # Sécurité et conseils 1. Pour une meilleure sécurité, faites en sorte que seul le répertoire `./public` soit accessible par le navigateur. Faites pointer un sous-domaine sur le répertoire `./public` par exemple -2. Dans tous les cas, assurez-vous que `./app/configuration/application.ini` ne puisse pas être téléchargé ! +2. Dans tous les cas, assurez-vous que `./data/application.ini` ne puisse pas être téléchargé ! 3. Le fichier de log peut être utile à lire si vous avez des soucis 4. Le fichier `./public/index.php` défini les chemins d'accès aux répertoires clés de l'application. Si vous les bougez, tout se passe ici. 5. Vous pouvez ajouter une tâche CRON sur le script d'actualisation des flux. Il s'agit d'un script PHP à exécuter avec la commande `php`. Par exemple, pour exécuter le script toutes les heures : diff --git a/actualize_script.php b/actualize_script.php index 65f9360a0..bc1d108bd 100755 --- a/actualize_script.php +++ b/actualize_script.php @@ -20,4 +20,4 @@ $front_controller = new App_FrontController (); $front_controller->init (); Session::_param('mail', true); // permet de se passer de la phase de connexion $front_controller->run (); -touch(PUBLIC_PATH . '/data/touch.txt'); +touch(DATA_PATH . '/touch.txt'); diff --git a/app/configuration/.gitignore b/app/configuration/.gitignore deleted file mode 100644 index 72e8ffc0d..000000000 --- a/app/configuration/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/app/controllers/entryController.php b/app/controllers/entryController.php index 4d2d92c1b..8016d719f 100755 --- a/app/controllers/entryController.php +++ b/app/controllers/entryController.php @@ -84,7 +84,7 @@ class entryController extends ActionController { $entryDAO = new EntryDAO(); $entryDAO->optimizeTable(); - touch(PUBLIC_PATH . '/data/touch.txt'); + touch(DATA_PATH . '/touch.txt'); $notif = array ( 'type' => 'good', diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 224d6fb9e..392abd3e1 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -277,7 +277,7 @@ class indexController extends ActionController { $res = json_decode ($result, true); if ($res['status'] == 'okay' && $res['email'] == $this->view->conf->mailLogin ()) { Session::_param ('mail', $res['email']); - touch(PUBLIC_PATH . '/data/touch.txt'); + touch(DATA_PATH . '/touch.txt'); } else { $res = array (); $res['status'] = 'failure'; @@ -290,6 +290,6 @@ class indexController extends ActionController { public function logoutAction () { $this->view->_useLayout (false); Session::_param ('mail'); - touch(PUBLIC_PATH . '/data/touch.txt'); + touch(DATA_PATH . '/touch.txt'); } } diff --git a/app/i18n/en.php b/app/i18n/en.php index eca1dd6d5..8243756bd 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -283,7 +283,7 @@ return array ( 'dom_is_nok' => 'You haven’t the necessary to browse the DOM (php-xml package can be useful)', 'cache_is_ok' => 'Permissions on cache directory are good', 'log_is_ok' => 'Permissions on logs directory are good', - 'conf_is_ok' => 'Permissions on configuration directory are good', + 'favicons_is_ok' => 'Permissions on favicons directory are good', 'data_is_ok' => 'Permissions on data directory are good', 'file_is_nok' => 'Check permissions on %s directory. HTTP server must have rights to write into', 'fix_errors_before' => 'Fix errors before skip to the next step.', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 2cddd4083..8040a6a44 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -283,7 +283,7 @@ return array ( 'dom_is_nok' => 'Vous ne disposez pas du nécessaire pour parcourir le DOM (voir du côté du paquet php-xml ?)', 'cache_is_ok' => 'Les droits sur le répertoire de cache sont bons', 'log_is_ok' => 'Les droits sur le répertoire des logs sont bons', - 'conf_is_ok' => 'Les droits sur le répertoire de configuration sont bons', + 'favicons_is_ok' => 'Les droits sur le répertoire des favicons sont bons', 'data_is_ok' => 'Les droits sur le répertoire de data sont bons', 'file_is_nok' => 'Veuillez vérifier les droits sur le répertoire %s. Le serveur HTTP doit être capable d’écrire dedans', 'fix_errors_before' => 'Veuillez corriger les erreurs avant de passer à l’étape suivante.', diff --git a/app/layout/layout.phtml b/app/layout/layout.phtml index ba4df4834..4232b714d 100644 --- a/app/layout/layout.phtml +++ b/app/layout/layout.phtml @@ -32,7 +32,7 @@ notification)) { - touch(PUBLIC_PATH . '/data/touch.txt', time() + 1); + touch(DATA_PATH . '/touch.txt', time() + 1); ?>
notification['content']; ?> diff --git a/app/models/Feed.php b/app/models/Feed.php index 2618d023f..adc8e1677 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -100,7 +100,7 @@ class Feed extends Model { return $this->nbNotRead; } public function favicon () { - $file = '/data/favicons/' . $this->id () . '.ico'; + $file = '/favicons/' . $this->id () . '.ico'; $favicon_url = Url::display ($file); if (!file_exists (PUBLIC_PATH . $file)) { diff --git a/app/models/RSSConfiguration.php b/app/models/RSSConfiguration.php index e79fd933b..f8379a625 100755 --- a/app/models/RSSConfiguration.php +++ b/app/models/RSSConfiguration.php @@ -348,7 +348,7 @@ class RSSConfigurationDAO extends Model_array { public $bottomline_link = 'yes'; public function __construct () { - parent::__construct (PUBLIC_PATH . '/data/Configuration.array.php'); + parent::__construct (DATA_PATH . '/Configuration.array.php'); // TODO : simplifier ce code, une boucle for() devrait suffir ! if (isset ($this->array['language'])) { diff --git a/cache/.gitignore b/cache/.gitignore deleted file mode 100644 index 72e8ffc0d..000000000 --- a/cache/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/constants.php b/constants.php index 260f01986..05d60b242 100644 --- a/constants.php +++ b/constants.php @@ -3,8 +3,11 @@ define('FRESHRSS_VERSION', '0.7-dev'); define('FRESHRSS_WEBSITE', 'http://marienfressinaud.github.io/FreshRSS/'); // Constantes de chemins -define ('PUBLIC_PATH', realpath (dirname (__FILE__) . '/public')); -define ('LIB_PATH', realpath (dirname (__FILE__) . '/lib')); -define ('APP_PATH', realpath (dirname (__FILE__) . '/app')); -define ('LOG_PATH', realpath (dirname (__FILE__) . '/log')); -define ('CACHE_PATH', realpath (dirname (__FILE__) . '/cache')); +define ('FRESHRSS_PATH', realpath (dirname (__FILE__))); +define ('PUBLIC_PATH', FRESHRSS_PATH . '/public'); +define ('DATA_PATH', FRESHRSS_PATH . '/data'); +define ('LIB_PATH', FRESHRSS_PATH . '/lib'); +define ('APP_PATH', FRESHRSS_PATH . '/app'); + +define ('LOG_PATH', DATA_PATH . '/log'); +define ('CACHE_PATH', DATA_PATH . '/cache'); diff --git a/data/.gitignore b/data/.gitignore new file mode 100644 index 000000000..0e407f099 --- /dev/null +++ b/data/.gitignore @@ -0,0 +1,6 @@ +cache +log +application.ini +Configuration.array.php +*.sqlite +touch.txt \ No newline at end of file diff --git a/lib/lib_rss.php b/lib/lib_rss.php index e4518ab4b..33f8641e1 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -168,9 +168,9 @@ function get_content_by_parsing ($url, $path) { /* Télécharge le favicon d'un site, le place sur le serveur et retourne l'URL */ function dowload_favicon ($website, $id) { $url = 'http://g.etfv.co/' . $website; - $favicons_dir = PUBLIC_PATH . '/data/favicons'; + $favicons_dir = PUBLIC_PATH . '/favicons'; $dest = $favicons_dir . '/' . $id . '.ico'; - $favicon_url = '/data/favicons/' . $id . '.ico'; + $favicon_url = '/favicons/' . $id . '.ico'; if (!is_dir ($favicons_dir)) { if (!mkdir ($favicons_dir, 0755, true)) { @@ -211,7 +211,7 @@ function dowload_favicon ($website, $id) { function lazyimg($content) { return preg_replace( '/]+?)src=[\'"]([^"\']+)[\'"]([^>]*)>/i', - '', + '', $content ); } diff --git a/lib/minz/Configuration.php b/lib/minz/Configuration.php index b296ec378..bdd6af0fb 100755 --- a/lib/minz/Configuration.php +++ b/lib/minz/Configuration.php @@ -8,7 +8,7 @@ * La classe Configuration permet de gérer la configuration de l'application */ class Configuration { - const CONF_PATH_NAME = '/configuration/application.ini'; + const CONF_PATH_NAME = '/application.ini'; /** * VERSION est la version actuelle de MINZ @@ -111,21 +111,21 @@ class Configuration { * @exception BadConfigurationException si CONF_PATH_NAME mal formaté */ private static function parseFile () { - if (!file_exists (APP_PATH . self::CONF_PATH_NAME)) { + if (!file_exists (DATA_PATH . self::CONF_PATH_NAME)) { throw new FileNotExistException ( - APP_PATH . self::CONF_PATH_NAME, + DATA_PATH . self::CONF_PATH_NAME, MinzException::ERROR ); } $ini_array = parse_ini_file ( - APP_PATH . self::CONF_PATH_NAME, + DATA_PATH . self::CONF_PATH_NAME, true ); if (!$ini_array) { throw new PermissionDeniedException ( - APP_PATH . self::CONF_PATH_NAME, + DATA_PATH . self::CONF_PATH_NAME, MinzException::ERROR ); } diff --git a/lib/minz/dao/Model_pdo.php b/lib/minz/dao/Model_pdo.php index dd75153be..beeb65ea8 100755 --- a/lib/minz/dao/Model_pdo.php +++ b/lib/minz/dao/Model_pdo.php @@ -49,9 +49,7 @@ class Model_pdo { PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' ); } elseif($type == 'sqlite') { - $string = $type - . ':/' . PUBLIC_PATH - . '/data/' . $db['base'] . '.sqlite'; //TODO: DEBUG UTF-8 http://www.siteduzero.com/forum/sujet/sqlite-connexion-utf-8-18797 + $string = $type . ':/' . DATA_PATH . $db['base'] . '.sqlite'; //TODO: DEBUG UTF-8 http://www.siteduzero.com/forum/sujet/sqlite-connexion-utf-8-18797 } $this->bd = new FreshPDO ( @@ -86,7 +84,7 @@ class Model_pdo { class FreshPDO extends PDO { private static function check($statement) { if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement)) { - touch(PUBLIC_PATH . '/data/touch.txt'); + touch(DATA_PATH . '/touch.txt'); } } diff --git a/log/.gitignore b/log/.gitignore deleted file mode 100644 index 72e8ffc0d..000000000 --- a/log/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/public/data/.gitignore b/public/data/.gitignore deleted file mode 100644 index 8498bc17e..000000000 --- a/public/data/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -favicons -Configuration.array.php -*.sqlite -touch.txt \ No newline at end of file diff --git a/public/data/grey.gif b/public/data/grey.gif deleted file mode 100644 index c7212bc1f..000000000 Binary files a/public/data/grey.gif and /dev/null differ diff --git a/public/index.php b/public/index.php index bda585592..d989bc11d 100755 --- a/public/index.php +++ b/public/index.php @@ -20,16 +20,16 @@ require('../constants.php'); -if (file_exists (PUBLIC_PATH . '/install.php')) { +if (file_exists ('install.php')) { include ('install.php'); } else { session_cache_limiter(''); require (LIB_PATH . '/http-conditional.php'); $dateLastModification = max( - @filemtime(PUBLIC_PATH . '/data/touch.txt'), + @filemtime(DATA_PATH . '/touch.txt'), @filemtime(LOG_PATH . '/application.log'), - @filemtime(PUBLIC_PATH . '/data/Configuration.array.php'), - @filemtime(APP_PATH . '/configuration/application.ini') + @filemtime(DATA_PATH . '/Configuration.array.php'), + @filemtime(DATA_PATH . '/application.ini') ); if (httpConditional($dateLastModification, 0, 0, false, false, true)) { exit(); //No need to send anything diff --git a/public/install.php b/public/install.php index 4c0da0ce5..085a412ff 100644 --- a/public/install.php +++ b/public/install.php @@ -166,7 +166,7 @@ function saveStep2 () { . small_hash ($_SESSION['base_url'] . $_SESSION['sel']); } - $file_data = PUBLIC_PATH . '/data/Configuration.array.php'; + $file_data = DATA_PATH . '/Configuration.array.php'; $f = fopen ($file_data, 'w'); writeLine ($f, ' $php ? 'ok' : 'ko', @@ -276,11 +276,11 @@ function checkStep1 () { 'curl' => $curl ? 'ok' : 'ko', 'pdo-mysql' => $pdo ? 'ok' : 'ko', 'dom' => $dom ? 'ok' : 'ko', + 'data' => $data ? 'ok' : 'ko', 'cache' => $cache ? 'ok' : 'ko', 'log' => $log ? 'ok' : 'ko', - 'configuration' => $conf ? 'ok' : 'ko', - 'data' => $data ? 'ok' : 'ko', - 'all' => $php && $minz && $curl && $pdo && $dom && $cache && $log && $conf && $data ? 'ok' : 'ko' + 'favicons' => $favicons ? 'ok' : 'ko', + 'all' => $php && $minz && $curl && $pdo && $dom && $data && $cache && $log && $favicons ? 'ok' : 'ko' ); } function checkStep2 () { @@ -289,7 +289,7 @@ function checkStep2 () { isset ($_SESSION['title']) && isset ($_SESSION['old_entries']) && isset ($_SESSION['mail_login']); - $data = file_exists (PUBLIC_PATH . '/data/Configuration.array.php'); + $data = file_exists (DATA_PATH . '/Configuration.array.php'); return array ( 'conf' => $conf ? 'ok' : 'ko', @@ -298,7 +298,7 @@ function checkStep2 () { ); } function checkStep3 () { - $conf = file_exists (APP_PATH . '/configuration/application.ini'); + $conf = file_exists (DATA_PATH . '/application.ini'); $bd = isset ($_SESSION['bd_type']) && isset ($_SESSION['bd_host']) && isset ($_SESSION['bd_user']) && @@ -337,8 +337,7 @@ function checkBD () { // on écrase la précédente connexion en sélectionnant la nouvelle BDD $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_name']; } elseif($_SESSION['bd_type'] == 'sqlite') { - $str = 'sqlite:' . PUBLIC_PATH - . '/data/' . $_SESSION['bd_name'] . '.sqlite'; + $str = 'sqlite:' . DATA_PATH . $_SESSION['bd_name'] . '.sqlite'; } $c = new PDO ($str, @@ -370,8 +369,8 @@ function checkBD () { $error = true; } - if ($error && file_exists (APP_PATH . '/configuration/application.ini')) { - unlink (APP_PATH . '/configuration/application.ini'); + if ($error && file_exists (DATA_PATH . '/application.ini')) { + unlink (DATA_PATH . '/application.ini'); } return !$error; @@ -448,28 +447,28 @@ function printStep1 () {

+ +

+ +

+ +

-

+

-

- - - -

- -

+

- -

+ +

-

+

diff --git a/public/themes/icons/grey.gif b/public/themes/icons/grey.gif new file mode 100644 index 000000000..c7212bc1f Binary files /dev/null and b/public/themes/icons/grey.gif differ -- cgit v1.2.3 From 8c8e5257d8d092822ca956d014ee74521d147744 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 17 Nov 2013 11:59:20 +0100 Subject: Corrige bug chargement JS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lorsque la vue par défaut était le mode lecture, le JS ne se chargeait pas. La faute au script LazyLoad qui n'était pas chargé correctement --- app/App_FrontController.php | 10 +++++++++- app/controllers/indexController.php | 5 ----- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'app/controllers/indexController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 2a7b86f1b..b175442d6 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -43,6 +43,12 @@ class App_FrontController extends FrontController { $this->conf = Session::param ('conf', new RSSConfiguration ()); View::_param ('conf', $this->conf); Session::_param ('language', $this->conf->language ()); + + $output = Request::param ('output'); + if(!$output) { + $output = $this->conf->viewMode(); + Request::_param ('output', $output); + } } private function loadStylesAndScripts () { @@ -53,11 +59,13 @@ class App_FrontController extends FrontController { } } View::appendStyle (Url::display ('/themes/printer/style.css?' . @filemtime(PUBLIC_PATH . '/themes/printer/style.css')), 'print'); + if (login_is_conf ($this->conf)) { View::appendScript ('https://login.persona.org/include.js'); } View::appendScript (Url::display ('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js'))); - if ($this->conf->lazyload () === 'yes' && ($this->conf->displayPosts () === 'yes' || Request::param ('output') === 'reader')) { + if ($this->conf->lazyload () === 'yes' && + ($this->conf->displayPosts () === 'yes' || Request::param ('output') === 'reader')) { View::appendScript (Url::display ('/scripts/jquery.lazyload.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.lazyload.min.js'))); } View::appendScript (Url::display ('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js'))); diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 392abd3e1..e4462e543 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -43,11 +43,6 @@ class indexController extends ActionController { $this->view->_useLayout (false); header('Content-Type: application/rss+xml; charset=utf-8'); } else { - if(!$output) { - $output = $this->view->conf->viewMode(); - Request::_param ('output', $output); - } - View::appendScript (Url::display ('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js'))); if ($output == 'global') { -- cgit v1.2.3 From 7cdc477c45a84bde56f5253ce34924f164e6ca0a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 28 Nov 2013 20:59:31 +0100 Subject: touch en microsecondes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Passage en microsecondes pour le touch (gestion du cache) pour éviter les problèmes en particulier dans le cas de requêtes de moins d'une seconde. Nouvelle fonction invalidateHttpCache() pour plus facilement changer de méthode de contrôle de fraîcheur de cache. Devrait résoudre https://github.com/marienfressinaud/FreshRSS/issues/296 --- actualize_script.php | 2 +- app/controllers/entryController.php | 2 +- app/controllers/indexController.php | 4 ++-- app/layout/layout.phtml | 2 +- app/models/RSSConfiguration.php | 2 +- lib/lib_rss.php | 4 ++++ lib/minz/dao/Model_pdo.php | 2 +- public/index.php | 7 ++++--- 8 files changed, 15 insertions(+), 10 deletions(-) (limited to 'app/controllers/indexController.php') diff --git a/actualize_script.php b/actualize_script.php index bc1d108bd..942070ccc 100755 --- a/actualize_script.php +++ b/actualize_script.php @@ -20,4 +20,4 @@ $front_controller = new App_FrontController (); $front_controller->init (); Session::_param('mail', true); // permet de se passer de la phase de connexion $front_controller->run (); -touch(DATA_PATH . '/touch.txt'); +invalidateHttpCache(); diff --git a/app/controllers/entryController.php b/app/controllers/entryController.php index fa34ad429..d92eb0ed3 100755 --- a/app/controllers/entryController.php +++ b/app/controllers/entryController.php @@ -84,7 +84,7 @@ class entryController extends ActionController { $entryDAO = new EntryDAO(); $entryDAO->optimizeTable(); - touch(DATA_PATH . '/touch.txt'); + invalidateHttpCache(); $notif = array ( 'type' => 'good', diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index e4462e543..8e6abd682 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -272,7 +272,7 @@ class indexController extends ActionController { $res = json_decode ($result, true); if ($res['status'] == 'okay' && $res['email'] == $this->view->conf->mailLogin ()) { Session::_param ('mail', $res['email']); - touch(DATA_PATH . '/touch.txt'); + invalidateHttpCache(); } else { $res = array (); $res['status'] = 'failure'; @@ -285,6 +285,6 @@ class indexController extends ActionController { public function logoutAction () { $this->view->_useLayout (false); Session::_param ('mail'); - touch(DATA_PATH . '/touch.txt'); + invalidateHttpCache(); } } diff --git a/app/layout/layout.phtml b/app/layout/layout.phtml index c53b28841..9b502275c 100644 --- a/app/layout/layout.phtml +++ b/app/layout/layout.phtml @@ -32,7 +32,7 @@ notification)) { - touch(DATA_PATH . '/touch.txt'); + invalidateHttpCache(); ?>
notification['content']; ?> diff --git a/app/models/RSSConfiguration.php b/app/models/RSSConfiguration.php index c36548e6f..fe6cd48d3 100755 --- a/app/models/RSSConfiguration.php +++ b/app/models/RSSConfiguration.php @@ -473,6 +473,6 @@ class RSSConfigurationDAO extends Model_array { } $this->writeFile($this->array); - touch(DATA_PATH . '/touch.txt'); + invalidateHttpCache(); } } diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 3c03f4281..5a74bfd0a 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -230,3 +230,7 @@ function lazyimg($content) { $content ); } + +function invalidateHttpCache() { + file_put_contents(DATA_PATH . '/touch.txt', microtime(true)); +} diff --git a/lib/minz/dao/Model_pdo.php b/lib/minz/dao/Model_pdo.php index 545f59e81..48c81d082 100755 --- a/lib/minz/dao/Model_pdo.php +++ b/lib/minz/dao/Model_pdo.php @@ -85,7 +85,7 @@ class Model_pdo { class FreshPDO extends PDO { private static function check($statement) { if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement)) { - touch(DATA_PATH . '/touch.txt'); + invalidateHttpCache(); } } diff --git a/public/index.php b/public/index.php index 9bf4fc073..cabd836d5 100755 --- a/public/index.php +++ b/public/index.php @@ -27,10 +27,11 @@ if (file_exists ('install.php')) { if (!file_exists(DATA_PATH . '/no-cache.txt')) { require (LIB_PATH . '/http-conditional.php'); $dateLastModification = max( - @filemtime(DATA_PATH . '/touch.txt') - 1, - @filemtime(LOG_PATH . '/application.log') - 1, - @filemtime(DATA_PATH . '/application.ini') - 1 + @filemtime(DATA_PATH . '/touch.txt'), + @filemtime(LOG_PATH . '/application.log'), + @filemtime(DATA_PATH . '/application.ini') ); + $_SERVER['QUERY_STRING'] .= '&utime=' . file_get_contents(DATA_PATH . '/touch.txt'); if (httpConditional($dateLastModification, 0, 0, false, false, true)) { exit(); //No need to send anything } -- cgit v1.2.3 From 37ce14c093c3dd009bcd7b627c5e819ac88dd5b7 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 30 Nov 2013 17:21:26 +0100 Subject: Recherche côté SQL avec LIKE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Premier essai de recherche côté base de données (à améliorer) https://github.com/marienfressinaud/FreshRSS/issues/204 Pour l'instant fait avec du LIKE et pas d'indexation texte complet. * Suppression de EntriesGetter car le code est devenu plus simple grâce au filtrage côté SQL * Uniformisation de get_c à une lettre ('all' devient 'a','favoris' devient 's' - pour "starred") pour simplifier le code * low_to_high par DESC, high_to_low par ASC * Réduction du nombre de créations de *DAO dans indexController * Refactorisation de checkAndProcessType() Pas encore trop testé... --- app/App_FrontController.php | 1 - app/controllers/configureController.php | 4 +- app/controllers/indexController.php | 254 +++++++++++++++----------------- app/layout/aside_flux.phtml | 4 +- app/layout/nav_menu.phtml | 13 +- app/models/EntriesGetter.php | 148 ------------------- app/models/Entry.php | 213 ++++++++++---------------- app/models/RSSConfiguration.php | 8 +- app/views/configure/display.phtml | 4 +- 9 files changed, 214 insertions(+), 435 deletions(-) delete mode 100644 app/models/EntriesGetter.php (limited to 'app/controllers/indexController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 40e31f549..d701e2944 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -33,7 +33,6 @@ class App_FrontController extends FrontController { include (APP_PATH . '/models/Category.php'); include (APP_PATH . '/models/Feed.php'); include (APP_PATH . '/models/Entry.php'); - include (APP_PATH . '/models/EntriesGetter.php'); include (APP_PATH . '/models/RSSPaginator.php'); include (APP_PATH . '/models/Log_Model.php'); } diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php index af6140b5d..424e3834a 100755 --- a/app/controllers/configureController.php +++ b/app/controllers/configureController.php @@ -158,12 +158,12 @@ class configureController extends ActionController { $language = Request::param ('language', 'en'); $nb = Request::param ('posts_per_page', 10); $mode = Request::param ('view_mode', 'normal'); - $view = Request::param ('default_view', 'all'); + $view = Request::param ('default_view', 'a'); $auto_load_more = Request::param ('auto_load_more', 'no'); $display = Request::param ('display_posts', 'no'); $onread_jump_next = Request::param ('onread_jump_next', 'no'); $lazyload = Request::param ('lazyload', 'no'); - $sort = Request::param ('sort_order', 'low_to_high'); + $sort = Request::param ('sort_order', 'DESC'); $old = Request::param ('old_entries', 3); $mail = Request::param ('mail_login', false); $anon = Request::param ('anon_access', 'no'); diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 8e6abd682..cf0e5024a 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -3,19 +3,29 @@ class indexController extends ActionController { private $get = false; private $nb_not_read_cat = 0; + private $entryDAO; + private $feedDAO; + private $catDAO; + + function __construct($router) { + parent::__construct($router); + $this->entryDAO = new EntryDAO (); + $this->feedDAO = new FeedDAO (); + $this->catDAO = new CategoryDAO (); + } public function indexAction () { $output = Request::param ('output'); $token = $this->view->conf->token(); $token_param = Request::param ('token', ''); - $token_is_ok = ($token != '' && $token == $token_param); + $token_is_ok = ($token != '' && $token === $token_param); // check if user is log in if(login_is_conf ($this->view->conf) && !is_logged() && - $this->view->conf->anonAccess() == 'no' && - !($output == 'rss' && $token_is_ok)) { + $this->view->conf->anonAccess() === 'no' && + !($output === 'rss' && $token_is_ok)) { return; } @@ -26,7 +36,7 @@ class indexController extends ActionController { $params['search'] = urlencode ($params['search']); } if (login_is_conf($this->view->conf) && - $this->view->conf->anonAccess() == 'no' && + $this->view->conf->anonAccess() === 'no' && $token != '') { $params['token'] = $token; } @@ -38,32 +48,25 @@ class indexController extends ActionController { $this->view->rss_title = View::title(); - if ($output == 'rss') { + if ($output === 'rss') { // no layout for RSS output $this->view->_useLayout (false); header('Content-Type: application/rss+xml; charset=utf-8'); } else { View::appendScript (Url::display ('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js'))); - if ($output == 'global') { + if ($output === 'global') { View::appendScript (Url::display ('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); } } - $entryDAO = new EntryDAO (); - $feedDAO = new FeedDAO (); - $catDAO = new CategoryDAO (); - - $this->view->cat_aside = $catDAO->listCategories (); - $this->view->nb_favorites = $entryDAO->countUnreadReadFavorites (); + $this->view->cat_aside = $this->catDAO->listCategories (); + $this->view->nb_favorites = $this->entryDAO->countUnreadReadFavorites (); $this->view->currentName = ''; $this->view->get_c = ''; $this->view->get_f = ''; - $type = $this->getType (); - $error = $this->checkAndProcessType ($type); - // mise à jour des titres $this->view->nb_not_read = HelperCategory::CountUnreads($this->view->cat_aside, 1); if ($this->view->nb_not_read > 0) { @@ -77,63 +80,73 @@ class indexController extends ActionController { ($this->nb_not_read_cat > 0 ? ' (' . $this->nb_not_read_cat . ')' : '') ); - if (!$error) { - // On récupère les différents éléments de filtrage - $this->view->state = $state = Request::param ('state', $this->view->conf->defaultView ()); - $filter = Request::param ('search', ''); - $this->view->order = $order = Request::param ('order', $this->view->conf->sortOrder ()); - $nb = Request::param ('nb', $this->view->conf->postsPerPage ()); - $first = Request::param ('next', ''); - - if ($state === 'not_read') { //Any unread article in this category at all? - switch ($type['type']) { - case 'all': - $hasUnread = $this->view->nb_not_read > 0; - break; - case 'favoris': - $hasUnread = $this->view->nb_favorites['unread'] > 0; - break; - case 'c': - $hasUnread = (!isset($this->view->cat_aside[$type['id']])) || ($this->view->cat_aside[$type['id']]->nbNotRead() > 0); - break; - case 'f': - $myFeed = HelperCategory::findFeed($this->view->cat_aside, $type['id']); - $hasUnread = ($myFeed === null) || ($myFeed->nbNotRead() > 0); - break; - default: - $hasUnread = true; - break; - } - if (!$hasUnread) { - $this->view->state = $state = 'all'; - } + $get = Request::param ('get', 'a'); + $getType = $get[0]; + $getId = substr ($get, 2); + if (!$this->checkAndProcessType ($getType, $getId)) { + Minz_Log::record ('Not found [' . $getType . '][' . $getId . ']', Minz_Log::DEBUG); + Error::error ( + 404, + array ('error' => array (Translate::t ('page_not_found'))) + ); + return; + } + + // On récupère les différents éléments de filtrage + $this->view->state = $state = Request::param ('state', $this->view->conf->defaultView ()); + $filter = Request::param ('search', ''); + if (!empty($filter)) { + $state = 'all'; //Search always in read and unread articles + } + $this->view->order = $order = Request::param ('order', $this->view->conf->sortOrder ()); + $nb = Request::param ('nb', $this->view->conf->postsPerPage ()); + $first = Request::param ('next', ''); + + if ($state === 'not_read') { //Any unread article in this category at all? + switch ($getType) { + case 'a': + $hasUnread = $this->view->nb_not_read > 0; + break; + case 's': + $hasUnread = $this->view->nb_favorites['unread'] > 0; + break; + case 'c': + $hasUnread = (!isset($this->view->cat_aside[$getId])) || ($this->view->cat_aside[$getId]->nbNotRead() > 0); + break; + case 'f': + $myFeed = HelperCategory::findFeed($this->view->cat_aside, $getId); + $hasUnread = ($myFeed === null) || ($myFeed->nbNotRead() > 0); + break; + default: + $hasUnread = true; + break; } + if (!$hasUnread) { + $this->view->state = $state = 'all'; + } + } - try { - // EntriesGetter permet de déporter la complexité du filtrage - $getter = new EntriesGetter ($type, $state, $filter, $order, $nb, $first); - $getter->execute (); - $entries = $getter->getPaginator (); - - // Si on a récupéré aucun article "non lus" - // on essaye de récupérer tous les articles - if ($state === 'not_read' && $entries->isEmpty ()) { //TODO: Remove in v0.8 - Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG); - $this->view->state = 'all'; - $getter->_state ('all'); - $getter->execute (); - $entries = $getter->getPaginator (); - } + try { + $entries = $this->entryDAO->listWhere($getType, $getId, $state, $order, $nb + 1, $first, $filter); + + // Si on a récupéré aucun article "non lus" + // on essaye de récupérer tous les articles + if ($state === 'not_read' && empty($entries)) { //TODO: Remove in v0.8 + Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG); + $this->view->state = 'all'; + $entries = $this->entryDAO->listWhere($getType, $getId, 'all', $order, $nb, $first, $filter); + } - $this->view->entryPaginator = $entries; - } catch (EntriesGetterException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); - Error::error ( - 404, - array ('error' => array (Translate::t ('page_not_found'))) - ); + if (count($entries) <= $nb) { + $next = ''; + } else { //We have more elements for pagination + $lastEntry = array_pop($entries); + $next = $lastEntry->id(); } - } else { + + $this->view->entryPaginator = new RSSPaginator ($entries, $next); + } catch (EntriesGetterException $e) { + Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); Error::error ( 404, array ('error' => array (Translate::t ('page_not_found'))) @@ -141,79 +154,50 @@ class indexController extends ActionController { } } - /* - * Détermine le type d'article à récupérer : - * "tous", "favoris", "public", "catégorie" ou "flux" - */ - private function getType () { - $get = Request::param ('get', 'all'); - $typeGet = $get[0]; - $id = substr ($get, 2); - - $type = null; - if ($get == 'all' || $get == 'favoris' || $get == 'public') { - $type = array ( - 'type' => $get, - 'id' => $get - ); - } elseif ($typeGet == 'f' || $typeGet == 'c') { - $type = array ( - 'type' => $typeGet, - 'id' => $id - ); - } - - return $type; - } /* * Vérifie que la catégorie / flux sélectionné existe * + Initialise correctement les variables de vue get_c et get_f * + Met à jour la variable $this->nb_not_read_cat */ - private function checkAndProcessType ($type) { - if ($type['type'] == 'all') { - $this->view->currentName = Translate::t ('your_rss_feeds'); - $this->view->get_c = $type['type']; - return false; - } elseif ($type['type'] == 'favoris') { - $this->view->currentName = Translate::t ('your_favorites'); - $this->view->get_c = $type['type']; - return false; - } elseif ($type['type'] == 'public') { - $this->view->currentName = Translate::t ('public'); - $this->view->get_c = $type['type']; - return false; - } elseif ($type['type'] == 'c') { - $cat = isset($this->view->cat_aside[$type['id']]) ? $this->view->cat_aside[$type['id']] : null; - if ($cat === null) { - $catDAO = new CategoryDAO (); - $cat = $catDAO->searchById ($type['id']); - } - if ($cat) { - $this->view->currentName = $cat->name (); - $this->nb_not_read_cat = $cat->nbNotRead (); - $this->view->get_c = $type['id']; - return false; - } else { + private function checkAndProcessType ($getType, $getId) { + switch ($getType) { + case 'a': + $this->view->currentName = Translate::t ('your_rss_feeds'); + $this->view->get_c = $getType; return true; - } - } elseif ($type['type'] == 'f') { - $feed = HelperCategory::findFeed($this->view->cat_aside, $type['id']); - if (empty($feed)) { - $feedDAO = new FeedDAO (); - $feed = $feedDAO->searchById ($type['id']); - } - if ($feed) { - $this->view->currentName = $feed->name (); - $this->nb_not_read_cat = $feed->nbNotRead (); - $this->view->get_f = $type['id']; - $this->view->get_c = $feed->category (); - return false; - } else { + case 's': + $this->view->currentName = Translate::t ('your_favorites'); + $this->view->get_c = $getType; return true; - } - } else { - return true; + case 'c': + $cat = isset($this->view->cat_aside[$getId]) ? $this->view->cat_aside[$getId] : null; + if ($cat === null) { + $cat = $this->catDAO->searchById ($getId); + } + if ($cat) { + $this->view->currentName = $cat->name (); + $this->nb_not_read_cat = $cat->nbNotRead (); + $this->view->get_c = $getId; + return true; + } else { + return false; + } + case 'f': + $feed = HelperCategory::findFeed($this->view->cat_aside, $getId); + if (empty($feed)) { + $feed = $this->feedDAO->searchById ($getId); + } + if ($feed) { + $this->view->currentName = $feed->name (); + $this->nb_not_read_cat = $feed->nbNotRead (); + $this->view->get_f = $getId; + $this->view->get_c = $feed->category (); + return true; + } else { + return false; + } + default: + return false; } } @@ -270,7 +254,7 @@ class indexController extends ActionController { curl_close ($ch); $res = json_decode ($result, true); - if ($res['status'] == 'okay' && $res['email'] == $this->view->conf->mailLogin ()) { + if ($res['status'] === 'okay' && $res['email'] === $this->view->conf->mailLogin ()) { Session::_param ('mail', $res['email']); invalidateHttpCache(); } else { diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtml index 918a44e01..ce5ded230 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -15,7 +15,7 @@
  • - + @@ -24,7 +24,7 @@
  • - + nb_favorites['all']); ?> diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index 0b95b4b02..289fe6542 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -11,9 +11,8 @@ $get = 'f_' . $this->get_f; $string_mark = Translate::t ('mark_feed_read'); } elseif ($this->get_c && - $this->get_c != 'all' && - $this->get_c != 'favoris' && - $this->get_c != 'public') { + $this->get_c != 'a' && + $this->get_c != 's') { $get = 'c_' . $this->get_c; $string_mark = Translate::t ('mark_cat_read'); } @@ -34,7 +33,7 @@ $anotherUnreadId = $cat->id (); if ($foundCurrent) break; } - $nextGet = empty ($anotherUnreadId) ? 'all' : 'c_' . $anotherUnreadId; + $nextGet = empty ($anotherUnreadId) ? 'a' : 'c_' . $anotherUnreadId; break; case 'f': foreach ($this->cat_aside as $cat) { @@ -149,15 +148,15 @@
  • order == 'low_to_high') { - $url_order['params']['order'] = 'high_to_low'; + if ($this->order === 'DESC') { + $url_order['params']['order'] = 'ASC'; ?> diff --git a/app/models/EntriesGetter.php b/app/models/EntriesGetter.php deleted file mode 100644 index ce026f252..000000000 --- a/app/models/EntriesGetter.php +++ /dev/null @@ -1,148 +0,0 @@ - 'all', - 'id' => 'all' - ); - private $state = 'all'; - private $filter = array ( - 'words' => array (), - 'tags' => array (), - ); - private $order = 'high_to_low'; - private $entries = array (); - - private $nb = 1; - private $first = ''; - private $next = ''; - - public function __construct ($type, $state, $filter, $order, $nb, $first = '') { - $this->_type ($type); - $this->_state ($state); - $this->_filter ($filter); - $this->_order ($order); - $this->nb = $nb; - $this->first = $first; - } - - public function type () { - return $this->type; - } - public function state () { - return $this->state; - } - public function filter () { - return $this->filter; - } - public function order () { - return $this->order; - } - public function entries () { - return $this->entries; - } - - public function _type ($value) { - if (!is_array ($value) || - !isset ($value['type']) || - !isset ($value['id'])) { - throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); - } - - $type = $value['type']; - $id = $value['id']; - - if ($type != 'all' && $type != 'favoris' && $type != 'public' && $type != 'c' && $type != 'f') { - throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); - } - - if (($type == 'all' || $type == 'favoris' || $type == 'public') && - ($type != $id)) { - throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); - } - - $this->type = $value; - } - public function _state ($value) { - if ($value != 'all' && $value != 'not_read' && $value != 'read') { - throw new EntriesGetterException ('Bad state line ' . __LINE__ . ' in file ' . __FILE__); - } - - $this->state = $value; - } - public function _filter ($value) { - $value = trim ($value); - $terms = explode (' ', $value); - - foreach ($terms as $word) { - if (!empty ($word) && $word[0] == '#' && isset ($word[1])) { - $tag = substr ($word, 1); - $this->filter['tags'][$tag] = $tag; - } elseif (!empty ($word)) { - $this->filter['words'][$word] = $word; - } - } - } - public function _order ($value) { - if ($value != 'high_to_low' && $value != 'low_to_high') { - throw new EntriesGetterException ('Bad order line ' . __LINE__ . ' in file ' . __FILE__); - } - - $this->order = $value; - } - - public function execute () { - $entryDAO = new EntryDAO (); - - HelperEntry::$nb = $this->nb; //TODO: Update: Now done in SQL - HelperEntry::$first = $this->first; //TODO: Update: Now done in SQL - HelperEntry::$filter = $this->filter; - - $sqlLimit = (empty ($this->filter['words']) && empty ($this->filter['tags'])) ? $this->nb : ''; //Disable SQL LIMIT optimisation during search //TODO: Do better! - - switch ($this->type['type']) { - case 'all': - list ($this->entries, $this->next) = $entryDAO->listEntries ( - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'favoris': - list ($this->entries, $this->next) = $entryDAO->listFavorites ( - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'c': - list ($this->entries, $this->next) = $entryDAO->listByCategory ( - $this->type['id'], - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'f': - list ($this->entries, $this->next) = $entryDAO->listByFeed ( - $this->type['id'], - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - default: - throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); - } - } - - public function getPaginator () { - $paginator = new RSSPaginator ($this->entries, $this->next); - - return $paginator; - } -} diff --git a/app/models/Entry.php b/app/models/Entry.php index 894985ece..915fbccc8 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -15,7 +15,7 @@ class Entry extends Model { private $tags; public function __construct ($feed = '', $guid = '', $title = '', $author = '', $content = '', - $link = '', $pubdate = 0, $is_read = false, $is_favorite = false) { + $link = '', $pubdate = 0, $is_read = false, $is_favorite = false, $tags = '') { $this->_guid ($guid); $this->_title ($title); $this->_author ($author); @@ -25,7 +25,7 @@ class Entry extends Model { $this->_isRead ($is_read); $this->_isFavorite ($is_favorite); $this->_feed ($feed); - $this->_tags (array ()); + $this->_tags (preg_split('/[\s#]/', $tags)); } public function id () { @@ -81,11 +81,7 @@ class Entry extends Model { } public function tags ($inString = false) { if ($inString) { - if (!empty ($this->tags)) { - return '#' . implode(' #', $this->tags); - } else { - return ''; - } + return empty ($this->tags) ? '' : '#' . implode(' #', $this->tags); } else { return $this->tags; } @@ -110,8 +106,8 @@ class Entry extends Model { $this->link = $value; } public function _date ($value) { - if (is_int (intval ($value))) { - $this->date = $value; + if (is_int ($value)) { + $this->date = intval ($value); } else { $this->date = time (); } @@ -448,13 +444,8 @@ class EntryDAO extends Model_pdo { $stm->execute ($values); $res = $stm->fetchAll (PDO::FETCH_ASSOC); - list ($entry, $next) = HelperEntry::daoToEntry ($res); - - if (isset ($entry[0])) { - return $entry[0]; - } else { - return false; - } + $entries = HelperEntry::daoToEntry ($res); + return isset ($entries[0]) ? $entries[0] : false; } public function searchById ($id) { @@ -466,60 +457,79 @@ class EntryDAO extends Model_pdo { $stm->execute ($values); $res = $stm->fetchAll (PDO::FETCH_ASSOC); - list ($entry, $next) = HelperEntry::daoToEntry ($res); - - if (isset ($entry[0])) { - return $entry[0]; - } else { - return false; + $entries = HelperEntry::daoToEntry ($res); + return isset ($entries[0]) ? $entries[0] : false; + } + + public function listWhere($type = 'a', $id = '', $state = 'all', $order = 'DESC', $limit = 1, $firstId = -1, $filter = '') { + $where = ''; + $values = array(); + switch ($type) { + case 'a': + $where .= 'priority > 0 '; + break; + case 's': + $where .= 'is_favorite = 1 '; + break; + case 'c': + $where .= 'category = ? '; + $values[] = intval($id); + break; + case 'f': + $where .= 'id_feed = ? '; + $values[] = intval($id); + break; + default: + throw new EntriesGetterException ('Bad type in Entry->listByType: [' . $type . ']!'); } - } - - private function listWhere ($where, $state, $order, $limitFromId = '', $limitCount = '', $values = array ()) { - if ($state === 'not_read') { - $where .= ' AND is_read = 0'; - } elseif ($state === 'read') { - $where .= ' AND is_read = 1'; + switch ($state) { + case 'all': + break; + case 'not_read': + $where .= 'AND is_read = 0 '; + break; + case 'read': + $where .= 'AND is_read = 1 '; + break; + default: + throw new EntriesGetterException ('Bad state in Entry->listByType: [' . $state . ']!'); } - if (!empty($limitFromId)) { - $where .= ' AND e.id ' . ($order === 'low_to_high' ? '<=' : '>=') . $limitFromId; + switch ($order) { + case 'DESC': + case 'ASC': + break; + default: + throw new EntriesGetterException ('Bad order in Entry->listByType: [' . $order . ']!'); } - - if ($order === 'low_to_high') { - $order = ' DESC'; - } else { - $order = ''; + if ($firstId > 0) { + $where .= 'AND e.id ' . ($order === 'DESC' ? '<=' : '>=') . $firstId . ' '; + } + $terms = explode(' ', trim($filter)); + sort($terms); //Put #tags first + foreach ($terms as $word) { + if (!empty($word)) { + if ($word[0] === '#' && isset($word[1])) { + $where .= 'AND tags LIKE "%' . $word . '%" '; + } elseif (!empty($word)) { + $where .= 'AND (e.title LIKE "%' . $word . '%" OR UNCOMPRESS(e.content_bin) LIKE "%' . $word . '%") '; + } + } } $sql = 'SELECT e.id, e.guid, e.title, e.author, UNCOMPRESS(e.content_bin) AS content, e.link, e.date, e.is_read, e.is_favorite, e.id_feed, e.tags ' . 'FROM `' . $this->prefix . 'entry` e ' - . 'INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id ' . $where - . ' ORDER BY e.id' . $order; + . 'INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id WHERE ' . $where + . 'ORDER BY e.id ' . $order; - if (empty($limitCount)) { - $limitCount = 20000; //TODO: FIXME: Hack temporaire en attendant la recherche côté base-de-données + if ($limit > 0) { + $sql .= ' LIMIT ' . $limit; //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/ } - //if (!empty($limitCount)) { - $sql .= ' LIMIT ' . ($limitCount + 2); //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/ - //} $stm = $this->bd->prepare ($sql); $stm->execute ($values); return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); } - public function listEntries ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere ('WHERE priority > 0', $state, $order, $limitFromId, $limitCount); - } - public function listFavorites ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere ('WHERE is_favorite = 1', $state, $order, $limitFromId, $limitCount); - } - public function listByCategory ($cat, $state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere ('WHERE category = ?', $state, $order, $limitFromId, $limitCount, array ($cat)); - } - public function listByFeed ($feed, $state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere ('WHERE id_feed = ?', $state, $order, $limitFromId, $limitCount, array ($feed)); - } public function listLastGuidsByFeed($id, $n) { $sql = 'SELECT guid FROM `' . $this->prefix . 'entry` WHERE id_feed=? ORDER BY id DESC LIMIT ' . intval($n); @@ -579,14 +589,6 @@ class EntryDAO extends Model_pdo { } class HelperEntry { - public static $nb = 1; - public static $first = ''; - - public static $filter = array ( - 'words' => array (), - 'tags' => array (), - ); - public static function daoToEntry ($listDAO) { $list = array (); @@ -594,80 +596,27 @@ class HelperEntry { $listDAO = array ($listDAO); } - $count = 0; - $first_is_found = false; - $break_after = false; - $next = ''; foreach ($listDAO as $key => $dao) { - $dao['tags'] = preg_split('/[\s#]/', $dao['tags']); - - if (self::tagsMatchEntry ($dao) && - self::searchMatchEntry ($dao)) { - if ($break_after) { - $next = $dao['id']; - break; - } - if ($first_is_found || $dao['id'] == self::$first || self::$first == '') { - $list[$key] = self::createEntry ($dao); - - $count++; - $first_is_found = true; //TODO: Update: Now done in SQL - } - if ($count >= self::$nb) { - $break_after = true; - } + $entry = new Entry ( + $dao['id_feed'], + $dao['guid'], + $dao['title'], + $dao['author'], + $dao['content'], + $dao['link'], + $dao['date'], + $dao['is_read'], + $dao['is_favorite'], + $dao['tags'] + ); + if (isset ($dao['id'])) { + $entry->_id ($dao['id']); } + $list[] = $entry; } unset ($listDAO); - return array ($list, $next); - } - - private static function createEntry ($dao) { - $entry = new Entry ( - $dao['id_feed'], - $dao['guid'], - $dao['title'], - $dao['author'], - $dao['content'], - $dao['link'], - $dao['date'], - $dao['is_read'], - $dao['is_favorite'] - ); - - $entry->_tags ($dao['tags']); - - if (isset ($dao['id'])) { - $entry->_id ($dao['id']); - } - - return $entry; - } - - private static function tagsMatchEntry ($dao) { - $tags = self::$filter['tags']; - foreach ($tags as $tag) { - if (!in_array ($tag, $dao['tags'])) { - return false; - } - } - - return true; - } - private static function searchMatchEntry ($dao) { - $words = self::$filter['words']; - - foreach ($words as $word) { - $word = strtolower ($word); - if (strpos (strtolower ($dao['title']), $word) === false && - strpos (strtolower ($dao['content']), $word) === false && - strpos (strtolower ($dao['link']), $word) === false) { - return false; - } - } - - return true; + return $list; } } diff --git a/app/models/RSSConfiguration.php b/app/models/RSSConfiguration.php index 37f26b1dd..007c1c0f5 100755 --- a/app/models/RSSConfiguration.php +++ b/app/models/RSSConfiguration.php @@ -213,11 +213,7 @@ class RSSConfiguration extends Model { } } public function _sortOrder ($value) { - if ($value == 'high_to_low') { - $this->sort_order = 'high_to_low'; - } else { - $this->sort_order = 'low_to_high'; - } + $this->sort_order = $value === 'ASC' ? 'ASC' : 'DESC'; } public function _oldEntries ($value) { if (is_int (intval ($value)) && $value > 0) { @@ -334,7 +330,7 @@ class RSSConfigurationDAO extends Model_array { public $display_posts = 'no'; public $onread_jump_next = 'yes'; public $lazyload = 'yes'; - public $sort_order = 'low_to_high'; + public $sort_order = 'DESC'; public $old_entries = 3; public $shortcuts = array ( 'mark_read' => 'r', diff --git a/app/views/configure/display.phtml b/app/views/configure/display.phtml index 52fd80185..90416145a 100644 --- a/app/views/configure/display.phtml +++ b/app/views/configure/display.phtml @@ -73,8 +73,8 @@
  • -- cgit v1.2.3 From 1e077160fca3306a273ecae5a366fd756c32baee Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 30 Nov 2013 22:47:48 +0100 Subject: Optimisation recherche et pagination MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Optimisation recherche SQL avec utilisation de HAVING plutôt que WHERE * Simplification et amélioration des performances en supprimant de RSSPaginator qui n'aidait plus vraiment et nécessitait plus de code et des copies de données. * Correction d'un bug dans le titre de la page introduit récemment, et simplification --- app/App_FrontController.php | 1 - app/controllers/indexController.php | 33 +++++++++++++--------------- app/layout/layout.phtml | 5 ++--- app/layout/nav_menu.phtml | 4 ++-- app/models/Entry.php | 11 +++++++--- app/models/RSSPaginator.php | 37 -------------------------------- app/views/helpers/pagination.phtml | 4 ++-- app/views/helpers/view/normal_view.phtml | 8 +++---- app/views/helpers/view/reader_view.phtml | 7 +++--- app/views/helpers/view/rss_view.phtml | 3 +-- 10 files changed, 36 insertions(+), 77 deletions(-) delete mode 100644 app/models/RSSPaginator.php (limited to 'app/controllers/indexController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index d701e2944..176677781 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -33,7 +33,6 @@ class App_FrontController extends FrontController { include (APP_PATH . '/models/Category.php'); include (APP_PATH . '/models/Feed.php'); include (APP_PATH . '/models/Entry.php'); - include (APP_PATH . '/models/RSSPaginator.php'); include (APP_PATH . '/models/Log_Model.php'); } diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index cf0e5024a..b3ae40847 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -46,8 +46,6 @@ class indexController extends ActionController { 'params' => $params ); - $this->view->rss_title = View::title(); - if ($output === 'rss') { // no layout for RSS output $this->view->_useLayout (false); @@ -67,19 +65,6 @@ class indexController extends ActionController { $this->view->get_c = ''; $this->view->get_f = ''; - // mise à jour des titres - $this->view->nb_not_read = HelperCategory::CountUnreads($this->view->cat_aside, 1); - if ($this->view->nb_not_read > 0) { - View::appendTitle (' (' . $this->view->nb_not_read . ')'); - } - View::prependTitle (' - '); - - $this->view->rss_title = $this->view->currentName . ' - ' . $this->view->rss_title; - View::prependTitle ( - $this->view->currentName . - ($this->nb_not_read_cat > 0 ? ' (' . $this->nb_not_read_cat . ')' : '') - ); - $get = Request::param ('get', 'a'); $getType = $get[0]; $getId = substr ($get, 2); @@ -92,6 +77,18 @@ class indexController extends ActionController { return; } + $this->view->nb_not_read = HelperCategory::CountUnreads($this->view->cat_aside, 1); + + // mise à jour des titres + if ($this->view->nb_not_read > 0) { + View::appendTitle (' (' . $this->view->nb_not_read . ')'); + } + View::prependTitle ( + $this->view->currentName . + ($this->nb_not_read_cat > 0 ? ' (' . $this->nb_not_read_cat . ')' : '') . + ' - ' + ); + // On récupère les différents éléments de filtrage $this->view->state = $state = Request::param ('state', $this->view->conf->defaultView ()); $filter = Request::param ('search', ''); @@ -138,13 +135,13 @@ class indexController extends ActionController { } if (count($entries) <= $nb) { - $next = ''; + $this->view->nextId = ''; } else { //We have more elements for pagination $lastEntry = array_pop($entries); - $next = $lastEntry->id(); + $this->view->nextId = $lastEntry->id(); } - $this->view->entryPaginator = new RSSPaginator ($entries, $next); + $this->view->entries = $entries; } catch (EntriesGetterException $e) { Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); Error::error ( diff --git a/app/layout/layout.phtml b/app/layout/layout.phtml index 9b502275c..6fc5c1cf0 100644 --- a/app/layout/layout.phtml +++ b/app/layout/layout.phtml @@ -10,10 +10,9 @@ renderHelper ('javascript_vars'); ?> //]]> entryPaginator) ? $this->entryPaginator->next() : ''; - if (!empty($next)) { + if (!empty($this->nextId)) { $params = Request::params (); - $params['next'] = $next; + $params['next'] = $this->nextId; ?> diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index 289fe6542..4b4945108 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -17,8 +17,6 @@ $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; @@ -54,6 +52,8 @@ break; } } + $p = isset($this->entries[0]) ? $this->entries[0] : null; + $idMax = $p === null ? '0' : $p->id(); $markReadUrl = _url ('entry', 'read', 'is_read', 1, 'get', $get, 'nextGet', $nextGet, 'idMax', $idMax); Session::_param ('markReadUrl', $markReadUrl); ?> diff --git a/app/models/Entry.php b/app/models/Entry.php index 915fbccc8..ae8facf68 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -504,14 +504,18 @@ class EntryDAO extends Model_pdo { if ($firstId > 0) { $where .= 'AND e.id ' . ($order === 'DESC' ? '<=' : '>=') . $firstId . ' '; } - $terms = explode(' ', trim($filter)); + $terms = array_unique(explode(' ', trim($filter))); sort($terms); //Put #tags first + $having = ''; foreach ($terms as $word) { if (!empty($word)) { if ($word[0] === '#' && isset($word[1])) { - $where .= 'AND tags LIKE "%' . $word . '%" '; + $having .= 'AND tags LIKE ? '; + $values[] = '%' . $word .'%'; } elseif (!empty($word)) { - $where .= 'AND (e.title LIKE "%' . $word . '%" OR UNCOMPRESS(e.content_bin) LIKE "%' . $word . '%") '; + $having .= 'AND (e.title LIKE ? OR content LIKE ?) '; + $values[] = '%' . $word .'%'; + $values[] = '%' . $word .'%'; } } } @@ -519,6 +523,7 @@ class EntryDAO extends Model_pdo { $sql = 'SELECT e.id, e.guid, e.title, e.author, UNCOMPRESS(e.content_bin) AS content, e.link, e.date, e.is_read, e.is_favorite, e.id_feed, e.tags ' . 'FROM `' . $this->prefix . 'entry` e ' . 'INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id WHERE ' . $where + . (empty($having) ? '' : 'HAVING' . substr($having, 3)) . 'ORDER BY e.id ' . $order; if ($limit > 0) { diff --git a/app/models/RSSPaginator.php b/app/models/RSSPaginator.php deleted file mode 100644 index 39146f1ba..000000000 --- a/app/models/RSSPaginator.php +++ /dev/null @@ -1,37 +0,0 @@ -items = $items; - $this->next = $next; - } - - public function isEmpty () { - return empty ($this->items); - } - - public function items () { - return $this->items; - } - - public function next () { - return $this->next; - } - - public function peek () { - return isset($this->items[0]) ? $this->items[0] : null; - } - - public function render ($view, $getteur) { - $view = APP_PATH . '/views/helpers/'.$view; - - if (file_exists ($view)) { - include ($view); - } - } -} diff --git a/app/views/helpers/pagination.phtml b/app/views/helpers/pagination.phtml index 0b0d2f5ba..408cfca1b 100755 --- a/app/views/helpers/pagination.phtml +++ b/app/views/helpers/pagination.phtml @@ -8,8 +8,8 @@
    diff --git a/app/layout/aside_feed.phtml b/app/layout/aside_feed.phtml index 2ce0b3ba4..7fbccce1e 100644 --- a/app/layout/aside_feed.phtml +++ b/app/layout/aside_feed.phtml @@ -1,17 +1,17 @@ diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtml index ce5ded230..9a6b16d58 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -1,23 +1,23 @@
    - +
      conf) || is_logged ()) { ?>
    • - - + +
    • conf)) { ?> -
    • +
    • @@ -25,8 +25,8 @@
    • @@ -38,7 +38,7 @@ get_c == $cat->id ()) { $c_active = true; } ?>
        @@ -49,7 +49,7 @@
      • ✇ @@ -67,13 +67,13 @@ diff --git a/app/layout/header.phtml b/app/layout/header.phtml index 12af6057a..6cb1380a3 100644 --- a/app/layout/header.phtml +++ b/app/layout/header.phtml @@ -1,9 +1,9 @@ conf)) { ?> @@ -12,8 +12,8 @@ @@ -24,25 +24,25 @@ $this->conf->anonAccess() == 'yes') { ?>
        - - + + - + - + - + - +
        @@ -53,19 +53,19 @@ @@ -74,7 +74,7 @@ if (login_is_conf ($this->conf) && !is_logged ()) { ?>
        - +
    diff --git a/app/layout/layout.phtml b/app/layout/layout.phtml index ac00e8fd0..b7c34f04e 100644 --- a/app/layout/layout.phtml +++ b/app/layout/layout.phtml @@ -11,19 +11,19 @@ //]]> nextId)) { - $params = Request::params (); + $params = Minz_Request::params (); $params['next'] = $this->nextId; ?> - + - + rss_url)) { ?> - + - - - - + + + + @@ -39,7 +39,7 @@ ?>
    notification['content']; ?> - +
    diff --git a/app/layout/nav_entries.phtml b/app/layout/nav_entries.phtml index 0811fe8fa..3141e92a0 100644 --- a/app/layout/nav_entries.phtml +++ b/app/layout/nav_entries.phtml @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index f3e985dc0..92a987aed 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -1,22 +1,22 @@