diff options
| author | 2013-11-12 18:49:18 +0100 | |
|---|---|---|
| committer | 2013-11-12 18:49:18 +0100 | |
| commit | 3f93866f38aff6b9f10d57472bf0ccf16d268499 (patch) | |
| tree | 47fee089a314541e57967413853a8d9f8fc0c8ae | |
| parent | 14342603a05b64294762c45798debe3a66db26eb (diff) | |
SQL : Optimisation vitesse
Optimisation de la vitesse de quelques requêtes, surtout après les
essais d'INDEX.
Suite de https://github.com/marienfressinaud/FreshRSS/issues/254
Note pour plus tard : il faudra supprimer les INDEX inutilisés.
| -rw-r--r-- | app/layout/aside_flux.phtml | 2 | ||||
| -rwxr-xr-x | app/models/Entry.php | 47 | ||||
| -rw-r--r-- | public/install.php | 2 |
3 files changed, 22 insertions, 29 deletions
diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtml index 511bb4564..87e2c000d 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -24,7 +24,7 @@ <div class="category favorites"> <a data-unread="<?php echo $this->nb_favorites['unread']; ?>" class="btn<?php echo $this->get_c == 'favoris' ? ' active' : ''; ?>" href="<?php echo _url ('index', 'index', 'get', 'favoris'); ?>"> <i class="icon i_bookmark"></i> - <?php echo Translate::t ('favorite_feeds', $this->nb_favorites['read'] + $this->nb_favorites['unread']); ?> + <?php echo Translate::t ('favorite_feeds', $this->nb_favorites['all']); ?> </a> </div> </li> diff --git a/app/models/Entry.php b/app/models/Entry.php index d03c3a3c1..5c6b379d8 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -449,42 +449,35 @@ class EntryDAO extends Model_pdo { } public function countUnreadRead () { - $sql = 'SELECT is_read, COUNT(*) AS count FROM ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id WHERE priority > 0 GROUP BY is_read'; + $sql = 'SELECT COUNT(e.id) AS count FROM ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id WHERE priority > 0' + . ' UNION SELECT COUNT(e.id) AS count FROM ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id WHERE priority > 0 AND is_read = 0'; $stm = $this->bd->prepare ($sql); $stm->execute (); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - - $readUnread = array('unread' => 0, 'read' => 0); - foreach ($res as $line) { - switch (intval($line['is_read'])) { - case 0: $readUnread['unread'] = intval($line['count']); break; - case 1: $readUnread['read'] = intval($line['count']); break; - } - } - return $readUnread; + $res = $stm->fetchAll (PDO::FETCH_COLUMN, 0); + return array('total' => $res[0], 'unread' => $res[1], 'read' => $res[0] - $res[1]); } - public function count () { //Deprecated: use countUnreadRead() instead - $unreadRead = $this->countUnreadRead (); //This makes better use of caching - return $unreadRead['unread'] + $unreadRead['read']; + public function count () { + $sql = 'SELECT COUNT(e.id) AS count FROM ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id WHERE priority > 0'; + $stm = $this->bd->prepare ($sql); + $stm->execute (); + $res = $stm->fetchAll (PDO::FETCH_COLUMN, 0); + return $res[0]; } - public function countNotRead () { //Deprecated: use countUnreadRead() instead - $unreadRead = $this->countUnreadRead (); //This makes better use of caching - return $unreadRead['unread']; + public function countNotRead () { + $sql = 'SELECT COUNT(e.id) AS count FROM ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id WHERE priority > 0 AND is_read = 0'; + $stm = $this->bd->prepare ($sql); + $stm->execute (); + $res = $stm->fetchAll (PDO::FETCH_COLUMN, 0); + return $res[0]; } public function countUnreadReadFavorites () { - $sql = 'SELECT is_read, COUNT(*) AS count FROM ' . $this->prefix . 'entry WHERE is_favorite=1 GROUP BY is_read'; + $sql = 'SELECT COUNT(id) FROM ' . $this->prefix . 'entry WHERE is_favorite=1' + . ' UNION SELECT COUNT(id) FROM ' . $this->prefix . 'entry WHERE is_favorite=1 AND is_read = 0'; $stm = $this->bd->prepare ($sql); $stm->execute (); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $readUnread = array('unread' => 0, 'read' => 0); - foreach ($res as $line) { - switch (intval($line['is_read'])) { - case 0: $readUnread['unread'] = intval($line['count']); break; - case 1: $readUnread['read'] = intval($line['count']); break; - } - } - return $readUnread; + $res = $stm->fetchAll (PDO::FETCH_COLUMN, 0); + return array('all' => $res[0], 'unread' => $res[1], 'read' => $res[0] - $res[1]); } public function optimizeTable() { diff --git a/public/install.php b/public/install.php index 7dde53e20..0dfe77c57 100644 --- a/public/install.php +++ b/public/install.php @@ -24,7 +24,7 @@ define ('SQL_REQ_FEED', 'CREATE TABLE IF NOT EXISTS `%sfeed` ( `category` char(6) DEFAULT \'000000\', `name` varchar(255) NOT NULL, `website` varchar(255) NOT NULL, - `description` varchar(1023) NOT NULL, + `description` text NOT NULL, `lastUpdate` int(11) NOT NULL, `priority` tinyint(2) NOT NULL DEFAULT \'10\', `pathEntries` varchar(511) DEFAULT NULL, |
