Browse Source

Disable SQL LIMIT optimisation during search

This patch is to make search work again after the new SQL optimisations,
by removing some of the optimisations when searching is used.
Optimisation of search is left for some future work.
The whole base is indeed transfered from MySQL to PHP, which is not
good.
Alexandre Alapetite 12 years ago
parent
commit
f55ae730e6
2 changed files with 13 additions and 11 deletions
  1. 7 5
      app/models/EntriesGetter.php
  2. 6 6
      app/models/Entry.php

+ 7 - 5
app/models/EntriesGetter.php

@@ -98,13 +98,15 @@ class EntriesGetter {
 		HelperEntry::$first = $this->first;	//TODO: Update: Now done in SQL
 		HelperEntry::$first = $this->first;	//TODO: Update: Now done in SQL
 		HelperEntry::$filter = $this->filter;
 		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']) {
 		switch ($this->type['type']) {
 		case 'all':
 		case 'all':
 			list ($this->entries, $this->next) = $entryDAO->listEntries (
 			list ($this->entries, $this->next) = $entryDAO->listEntries (
 				$this->state,
 				$this->state,
 				$this->order,
 				$this->order,
 				$this->first,
 				$this->first,
-				$this->nb
+				$sqlLimit
 			);
 			);
 			break;
 			break;
 		case 'favoris':
 		case 'favoris':
@@ -112,7 +114,7 @@ class EntriesGetter {
 				$this->state,
 				$this->state,
 				$this->order,
 				$this->order,
 				$this->first,
 				$this->first,
-				$this->nb
+				$sqlLimit
 			);
 			);
 			break;
 			break;
 		case 'public':
 		case 'public':
@@ -120,7 +122,7 @@ class EntriesGetter {
 				$this->state,
 				$this->state,
 				$this->order,
 				$this->order,
 				$this->first,
 				$this->first,
-				$this->nb
+				$sqlLimit
 			);
 			);
 			break;
 			break;
 		case 'c':
 		case 'c':
@@ -129,7 +131,7 @@ class EntriesGetter {
 				$this->state,
 				$this->state,
 				$this->order,
 				$this->order,
 				$this->first,
 				$this->first,
-				$this->nb
+				$sqlLimit
 			);
 			);
 			break;
 			break;
 		case 'f':
 		case 'f':
@@ -138,7 +140,7 @@ class EntriesGetter {
 				$this->state,
 				$this->state,
 				$this->order,
 				$this->order,
 				$this->first,
 				$this->first,
-				$this->nb
+				$sqlLimit
 			);
 			);
 			break;
 			break;
 		default:
 		default:

+ 6 - 6
app/models/Entry.php

@@ -396,7 +396,7 @@ class EntryDAO extends Model_pdo {
 		     . ' ORDER BY date' . $order . ', id' . $order;
 		     . ' ORDER BY date' . $order . ', id' . $order;
 
 
 		if (!empty($limitCount)) {
 		if (!empty($limitCount)) {
-			$sql .= ' LIMIT ' . $limitCount;	//TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/
+			$sql .= ' LIMIT ' . ($limitCount + 1);	//TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/
 		}
 		}
 
 
 		$stm = $this->bd->prepare ($sql);
 		$stm = $this->bd->prepare ($sql);
@@ -405,19 +405,19 @@ class EntryDAO extends Model_pdo {
 		return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
 		return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
 	}
 	}
 	public function listEntries ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') {
 	public function listEntries ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') {
-		return $this->listWhere (' WHERE priority > 0', $state, $order, $limitFromId, $limitCount + 1);
+		return $this->listWhere (' WHERE priority > 0', $state, $order, $limitFromId, $limitCount);
 	}
 	}
 	public function listFavorites ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') {
 	public function listFavorites ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') {
-		return $this->listWhere (' WHERE is_favorite = 1', $state, $order, $limitFromId, $limitCount + 1);
+		return $this->listWhere (' WHERE is_favorite = 1', $state, $order, $limitFromId, $limitCount);
 	}
 	}
 	public function listPublic ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') {
 	public function listPublic ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') {
-		return $this->listWhere (' WHERE is_public = 1', $state, $order, $limitFromId, $limitCount + 1);
+		return $this->listWhere (' WHERE is_public = 1', $state, $order, $limitFromId, $limitCount);
 	}
 	}
 	public function listByCategory ($cat, $state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') {
 	public function listByCategory ($cat, $state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') {
-		return $this->listWhere (' WHERE category = ?', $state, $order, $limitFromId, $limitCount + 1, array ($cat));
+		return $this->listWhere (' WHERE category = ?', $state, $order, $limitFromId, $limitCount, array ($cat));
 	}
 	}
 	public function listByFeed ($feed, $state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') {
 	public function listByFeed ($feed, $state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') {
-		return $this->listWhere (' WHERE id_feed = ?', $state, $order, $limitFromId, $limitCount + 1, array ($feed));
+		return $this->listWhere (' WHERE id_feed = ?', $state, $order, $limitFromId, $limitCount, array ($feed));
 	}
 	}
 
 
 	public function countUnreadRead () {
 	public function countUnreadRead () {