A free, self-hostable news aggregator…
SQL : Optimisation vitesse
Alexandre Alapetite3f93866f38af
diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtmlindex 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.phpindex 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.phpindex 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,