diff options
| author | 2013-11-30 22:47:48 +0100 | |
|---|---|---|
| committer | 2013-11-30 22:47:48 +0100 | |
| commit | 1e077160fca3306a273ecae5a366fd756c32baee (patch) | |
| tree | 942066b18dbf63c63f2dbddb547ed3e9bcc66d8d /app/models/Entry.php | |
| parent | 37ce14c093c3dd009bcd7b627c5e819ac88dd5b7 (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/Entry.php')
| -rwxr-xr-x | app/models/Entry.php | 11 |
1 files changed, 8 insertions, 3 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) { |
