Ver Fonte

Suppression multiples requêtes count

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
Alexandre Alapetite há 12 anos atrás
pai
commit
58cb842966

+ 0 - 4
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 ());
 	}
 

+ 16 - 12
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 ();

+ 1 - 1
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',

+ 1 - 1
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',

+ 1 - 1
app/layout/aside_flux.phtml

@@ -15,7 +15,7 @@
 			<div class="category all">
 				<a data-unread="<?php echo $this->nb_not_read; ?>" class="btn<?php echo $this->get_c == 'all' ? ' active' : ''; ?>" href="<?php echo _url ('index', 'index'); ?>">
 					<i class="icon i_all"></i>
-					<?php echo Translate::t ('all_feeds', $this->nb_total); ?>
+					<?php echo Translate::t ('all_feeds'); ?>
 				</a>
 			</div>
 		</li>