From f855dbdca6e95ac367b7a9dae9d3a866e1f85d37 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 2 Sep 2013 22:06:51 +0200 Subject: SQL and model optimisation Big effect (on speed and memory), but few changes :-) Drastically reduced the number of SQL requests needed (from 233 down to 8 to load the home page with my own data set = 140 feeds in 15 categories). Drastically reduced the amount of data transferred from MySQL to PHP. --- app/models/Feed.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'app/models/Feed.php') diff --git a/app/models/Feed.php b/app/models/Feed.php index 678809af6..e9e21f06a 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -4,6 +4,7 @@ class Feed extends Model { private $id = null; private $url; private $category = '000000'; + private $nbNotRead = -1; private $entries = null; private $name = ''; private $website = ''; @@ -82,8 +83,12 @@ class Feed extends Model { return $feedDAO->countEntries ($this->id ()); } public function nbNotRead () { + if ($this->nbNotRead < 0) { $feedDAO = new FeedDAO (); - return $feedDAO->countNotRead ($this->id ()); + $this->nbNotRead = $feedDAO->countNotRead ($this->id ()); + } + + return $this->nbNotRead; } public function favicon () { $file = '/data/favicons/' . $this->id () . '.ico'; @@ -162,6 +167,12 @@ class Feed extends Model { } $this->keep_history = $value; } + public function _nbNotRead ($value) { //Alex + if (!is_int (intval ($value))) { + $value = -1; + } + $this->nbNotRead = $value; + } public function load () { if (!is_null ($this->url)) { @@ -506,7 +517,9 @@ class HelperFeed { $list[$key]->_httpAuth (base64_decode ($dao['httpAuth'])); $list[$key]->_error ($dao['error']); $list[$key]->_keepHistory ($dao['keep_history']); - + if (isset ($dao['nbNotRead'])) { + $list[$key]->_nbNotRead ($dao['nbNotRead']); + } if (isset ($dao['id'])) { $list[$key]->_id ($dao['id']); } -- cgit v1.2.3 From 7627970862e03a9061ddced3423689e9dccd6f45 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 12 Sep 2013 22:41:09 +0200 Subject: Corrected bug with the default "No Category" The SQL optimisation patch had introduced a bug with "No Category", now solved --- app/controllers/feedController.php | 1 + app/models/Category.php | 2 +- app/models/Feed.php | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) (limited to 'app/models/Feed.php') diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php index 18a46f322..d685857bd 100755 --- a/app/controllers/feedController.php +++ b/app/controllers/feedController.php @@ -17,6 +17,7 @@ class feedController extends ActionController { if (Request::isPost ()) { $url = Request::param ('url_rss'); $cat = Request::param ('category'); + if (empty($cat)) $cat = '000000'; $user = Request::param ('username'); $pass = Request::param ('password'); $params = array (); diff --git a/app/models/Category.php b/app/models/Category.php index 362bce621..70cc0d16f 100755 --- a/app/models/Category.php +++ b/app/models/Category.php @@ -179,7 +179,7 @@ class CategoryDAO extends Model_pdo { if ($prePopulateFeeds) { $sql = 'SELECT c.id as c_id, c.name as c_name, c.color as c_color, count(e.id) as nbNotRead, f.* ' . 'FROM ' . $this->prefix . 'category c ' - . 'INNER JOIN ' . $this->prefix . 'feed f ON f.category = c.id ' + . 'LEFT OUTER JOIN ' . $this->prefix . 'feed f ON f.category = c.id ' . 'LEFT OUTER JOIN ' . $this->prefix . 'entry e ON e.id_feed = f.id AND e.is_read = 0 ' . 'GROUP BY f.id ' . 'ORDER BY c.name, f.name'; diff --git a/app/models/Feed.php b/app/models/Feed.php index e9e21f06a..2a93be757 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -502,6 +502,9 @@ class HelperFeed { } foreach ($listDAO as $key => $dao) { + if (empty ($dao['url'])) { + continue; + } if (isset ($dao['id'])) { $key = $dao['id']; } -- cgit v1.2.3 From e19695e14bdf3ea1baf04141f346060751eb1789 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 14 Sep 2013 22:10:35 +0200 Subject: Issue #155 : correction fonction _nbNotRead MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit intval renvoyant toujours un integer, le test is_int() passait toujours, c'est corrigé maintenant --- app/models/Feed.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'app/models/Feed.php') diff --git a/app/models/Feed.php b/app/models/Feed.php index f72008c05..061a6a33a 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -167,11 +167,12 @@ class Feed extends Model { } $this->keep_history = $value; } - public function _nbNotRead ($value) { //Alex - if (!is_int (intval ($value))) { + public function _nbNotRead ($value) { + if (!is_int ($value)) { $value = -1; } - $this->nbNotRead = $value; + + $this->nbNotRead = intval ($value); } public function load () { -- cgit v1.2.3