Kaynağa Gözat

SQL performance: Removed filter to hide old articles

As discussed on
https://github.com/marienfressinaud/FreshRSS/issues/493#issuecomment-56266415
For performance, but this is also a good simplification.
Will help with PostgreSQL
https://github.com/marienfressinaud/FreshRSS/issues/416 and SQLite too
https://github.com/marienfressinaud/FreshRSS/issues/100 because the main
query becomes simpler.

Me may need to introduce another system to hide old articles, if this is
a problem for some users.
Also, the feature showing "empty feeds" in another colour may need to be
adapted.
Alexandre Alapetite 11 yıl önce
ebeveyn
işleme
a5a0bd9a35
2 değiştirilmiş dosya ile 13 ekleme ve 28 silme
  1. 3 9
      app/Controllers/indexController.php
  2. 10 19
      app/Models/EntryDAO.php

+ 3 - 9
app/Controllers/indexController.php

@@ -113,16 +113,10 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 			}
 		}
 
-		$today = @strtotime('today');
-		$this->view->today = $today;
-
-		// on calcule la date des articles les plus anciens qu'on affiche
-		$nb_month_old = $this->view->conf->old_entries;
-		$date_min = $today - (3600 * 24 * 30 * $nb_month_old);	//Do not use a fast changing value such as time() to allow SQL caching
-		$keepHistoryDefault = $this->view->conf->keep_history_default;
+		$this->view->today = @strtotime('today');
 
 		try {
-			$entries = $entryDAO->listWhere($getType, $getId, $this->view->state, $order, $nb + 1, $first, $filter, $date_min, true, $keepHistoryDefault);
+			$entries = $entryDAO->listWhere($getType, $getId, $this->view->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
@@ -135,7 +129,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 					Minz_Log::record('Failed to automatically correct nbNotRead! ' + $ex->getMessage(), Minz_Log::NOTICE);
 				}
 				$this->view->state = FreshRSS_Entry::STATE_ALL;
-				$entries = $entryDAO->listWhere($getType, $getId, $this->view->state, $order, $nb, $first, $filter, $date_min, true, $keepHistoryDefault);
+				$entries = $entryDAO->listWhere($getType, $getId, $this->view->state, $order, $nb, $first, $filter);
 			}
 			Minz_Request::_param('state', $this->view->state);
 

+ 10 - 19
app/Models/EntryDAO.php

@@ -299,7 +299,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
 		return 'CONCAT(' . $s1 . ',' . $s2 . ')';	//MySQL
 	}
 
-	private function sqlListWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) {
+	private function sqlListWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0) {
 		if (!$state) {
 			$state = FreshRSS_Entry::STATE_ALL;
 		}
@@ -356,23 +356,14 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
 			default:
 				throw new FreshRSS_EntriesGetter_Exception('Bad order in Entry->listByType: [' . $order . ']!');
 		}
-		if ($firstId === '' && parent::$sharedDbType === 'mysql') {
-			$firstId = $order === 'DESC' ? '9000000000'. '000000' : '0';	//MySQL optimization. Tested on MySQL 5.5 with 150k articles
-		}
+		/*if ($firstId === '' && parent::$sharedDbType === 'mysql') {
+			$firstId = $order === 'DESC' ? '9000000000'. '000000' : '0';	//MySQL optimization. TODO: check if this is needed again, after the filtering for old articles has been removed in 0.9-dev
+		}*/
 		if ($firstId !== '') {
 			$where .= 'AND e1.id ' . ($order === 'DESC' ? '<=' : '>=') . $firstId . ' ';
 		}
-		if (($date_min > 0) && ($type !== 's')) {
-			$where .= 'AND (e1.id >= ' . $date_min . '000000';
-			if ($showOlderUnreadsorFavorites) {	//Lax date constraint
-				$where .= ' OR e1.is_read=0 OR e1.is_favorite=1 OR (f.keep_history <> 0';
-				if (intval($keepHistoryDefault) === 0) {
-					$where .= ' AND f.keep_history <> -2';	//default
-				}
-				$where .= ')';
-			}
-			$where .= ') ';
-			$joinFeed = true;
+		if ($date_min > 0) {
+			$where .= 'AND e1.id >= ' . $date_min . '000000 ';
 		}
 		$search = '';
 		if ($filter !== '') {
@@ -434,8 +425,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
 			. ($limit > 0 ? ' LIMIT ' . $limit : ''));	//TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/
 	}
 
-	public function listWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) {
-		list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min, $showOlderUnreadsorFavorites, $keepHistoryDefault);
+	public function listWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0) {
+		list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min);
 
 		$sql = 'SELECT e.id, e.guid, e.title, e.author, '
 		     . ($this->isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content')
@@ -452,8 +443,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
 		return self::daoToEntry($stm->fetchAll(PDO::FETCH_ASSOC));
 	}
 
-	public function listIdsWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) {	//For API
-		list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min, $showOlderUnreadsorFavorites, $keepHistoryDefault);
+	public function listIdsWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0) {	//For API
+		list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min);
 
 		$stm = $this->bd->prepare($sql);
 		$stm->execute($values);