aboutsummaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-11-30 22:47:48 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-11-30 22:47:48 +0100
commit1e077160fca3306a273ecae5a366fd756c32baee (patch)
tree942066b18dbf63c63f2dbddb547ed3e9bcc66d8d /app/models
parent37ce14c093c3dd009bcd7b627c5e819ac88dd5b7 (diff)
Optimisation recherche et pagination
* 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
Diffstat (limited to 'app/models')
-rwxr-xr-xapp/models/Entry.php11
-rw-r--r--app/models/RSSPaginator.php37
2 files changed, 8 insertions, 40 deletions
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 @@
-<?php
-
-// Un système de pagination beaucoup plus simple que Paginator
-// mais mieux adapté à nos besoins
-class RSSPaginator {
- private $items = array ();
- private $next = '';
-
- public function __construct ($items, $next) {
- $this->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);
- }
- }
-}