aboutsummaryrefslogtreecommitdiff
path: root/app/Models/EntryDAO.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-15 16:01:37 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-15 16:01:37 +0100
commita2421185d0bc9a0e177b6ecbf98bb17086d43386 (patch)
tree4cf0ae51ad68b2e7753d19941615ab610a5013f0 /app/Models/EntryDAO.php
parentce3801e5acf22e64cb53cfad21ced1b962674a91 (diff)
SQL : Petite amélioration de la requête principale
En particulier pour les favoris, où cela évite une jointure.
Diffstat (limited to 'app/Models/EntryDAO.php')
-rw-r--r--app/Models/EntryDAO.php23
1 files changed, 14 insertions, 9 deletions
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 1bce6cbf2..f80fe9b77 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -261,20 +261,23 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
public function listWhere($type = 'a', $id = '', $state = 'all', $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0) {
$where = '';
+ $joinFeed = false;
$values = array();
switch ($type) {
case 'a':
- $where .= 'priority > 0 ';
+ $where .= 'f.priority > 0 ';
+ $joinFeed = true;
break;
case 's':
- $where .= 'is_favorite = 1 ';
+ $where .= 'e.is_favorite = 1 ';
break;
case 'c':
- $where .= 'category = ? ';
+ $where .= 'f.category = ? ';
$values[] = intval($id);
+ $joinFeed = true;
break;
case 'f':
- $where .= 'id_feed = ? ';
+ $where .= 'e.id_feed = ? ';
$values[] = intval($id);
break;
default:
@@ -284,10 +287,10 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
case 'all':
break;
case 'not_read':
- $where .= 'AND is_read = 0 ';
+ $where .= 'AND e.is_read = 0 ';
break;
case 'read':
- $where .= 'AND is_read = 1 ';
+ $where .= 'AND e.is_read = 1 ';
break;
default:
throw new FreshRSS_EntriesGetter_Exception ('Bad state in Entry->listByType: [' . $state . ']!');
@@ -302,8 +305,9 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
if ($firstId !== '') {
$where .= 'AND e.id ' . ($order === 'DESC' ? '<=' : '>=') . $firstId . ' ';
}
- if ($date_min > 0) {
+ if (($date_min > 0) && ($type !== 's')) {
$where .= 'AND (e.id >= ' . $date_min . '000000 OR e.is_favorite = 1 OR f.keep_history = 1) ';
+ $joinFeed = true;
}
$terms = array_unique(explode(' ', trim($filter)));
sort($terms); //Put #tags first
@@ -311,7 +315,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
foreach ($terms as $word) {
if (!empty($word)) {
if ($word[0] === '#' && isset($word[1])) {
- $having .= 'AND tags LIKE ? ';
+ $having .= 'AND e.tags LIKE ? ';
$values[] = '%' . $word .'%';
} elseif (!empty($word)) {
$having .= 'AND (e.title LIKE ? OR content LIKE ?) ';
@@ -323,7 +327,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
$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
+ . ($joinFeed ? '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;