diff options
| author | 2012-12-08 13:28:53 +0100 | |
|---|---|---|
| committer | 2012-12-08 13:28:53 +0100 | |
| commit | ba37c6e06fc7db2d33eab0a5b120c0186039a1ca (patch) | |
| tree | 7f9ac69dddd0ac1d07781f7d267b6d6e0ef47a4c | |
| parent | acc0c6f424fb7d4a4ab8ac52995ac746b0c1c1a5 (diff) | |
optimisation de la mise à jour des flux --> attention, modification de la BDD nécessaire
| -rwxr-xr-x | app/controllers/feedController.php | 92 | ||||
| -rw-r--r-- | app/models/Feed.php | 35 | ||||
| -rw-r--r-- | app/views/javascript/main.phtml | 8 | ||||
| -rw-r--r-- | public/theme/base.css | 8 |
4 files changed, 104 insertions, 39 deletions
diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php index d459ba0cb..9a56e97cf 100755 --- a/app/controllers/feedController.php +++ b/app/controllers/feedController.php @@ -23,6 +23,7 @@ class feedController extends ActionController { 'name' => $feed->name (), 'website' => $feed->website (), 'description' => $feed->description (), + 'lastUpdate' => time () ); $feedDAO->addFeed ($values); @@ -68,30 +69,44 @@ class feedController extends ActionController { $feedDAO = new FeedDAO (); $entryDAO = new EntryDAO (); - $feeds = $feedDAO->listFeeds (); + $feeds = $feedDAO->listFeedsOrderUpdate (); + // pour ne pas ajouter des entrées trop anciennes + $nb_month_old = $this->view->conf->oldEntries (); + $date_min = time () - (60 * 60 * 24 * 30 * $nb_month_old); + + $i = 0; foreach ($feeds as $feed) { $feed->load (); $entries = $feed->entries (); foreach ($entries as $entry) { - $values = array ( - 'id' => $entry->id (), - 'guid' => $entry->guid (), - 'title' => $entry->title (), - 'author' => $entry->author (), - 'content' => $entry->content (), - 'link' => $entry->link (), - 'date' => $entry->date (true), - 'is_read' => $entry->isRead (), - 'is_favorite' => $entry->isFavorite (), - 'id_feed' => $feed->id () - ); - $entryDAO->addEntry ($values); + if ($entry->date (true) >= $date_min) { + $values = array ( + 'id' => $entry->id (), + 'guid' => $entry->guid (), + 'title' => $entry->title (), + 'author' => $entry->author (), + 'content' => $entry->content (), + 'link' => $entry->link (), + 'date' => $entry->date (true), + 'is_read' => $entry->isRead (), + 'is_favorite' => $entry->isFavorite (), + 'id_feed' => $feed->id () + ); + $entryDAO->addEntry ($values); + } + } + + $feedDAO->updateLastUpdate ($feed->id ()); + + $i++; + if ($i >= 10) { + break; } } - $entryDAO->cleanOldEntries ($this->view->conf->oldEntries ()); + $entryDAO->cleanOldEntries ($nb_month_old); // notif $notif = array ( @@ -125,26 +140,38 @@ class feedController extends ActionController { ); $catDAO->addCategory ($values); } + + $nb_month_old = $this->view->conf->oldEntries (); + $date_min = time () - (60 * 60 * 24 * 30 * $nb_month_old); + $i = 0; foreach ($feeds as $feed) { $feed->load (); - $entries = $feed->entries (); - - // Chargement du flux - foreach ($entries as $entry) { - $values = array ( - 'id' => $entry->id (), - 'guid' => $entry->guid (), - 'title' => $entry->title (), - 'author' => $entry->author (), - 'content' => $entry->content (), - 'link' => $entry->link (), - 'date' => $entry->date (true), - 'is_read' => $entry->isRead (), - 'is_favorite' => $entry->isFavorite (), - 'id_feed' => $feed->id () - ); - $entryDAO->addEntry ($values); + + // on ajoute les entrées que de 10 flux pour limiter un peu la charge + // si on ajoute pas les entrées du flux, alors on met la date du dernier update à 0 + $update = 0; + $i++; + if ($i < 10) { + $update = time (); + $entries = $feed->entries (); + foreach ($entries as $entry) { + if ($entry->date (true) >= $date_min) { + $values = array ( + 'id' => $entry->id (), + 'guid' => $entry->guid (), + 'title' => $entry->title (), + 'author' => $entry->author (), + 'content' => $entry->content (), + 'link' => $entry->link (), + 'date' => $entry->date (true), + 'is_read' => $entry->isRead (), + 'is_favorite' => $entry->isFavorite (), + 'id_feed' => $feed->id () + ); + $entryDAO->addEntry ($values); + } + } } // Enregistrement du flux @@ -155,6 +182,7 @@ class feedController extends ActionController { 'name' => $feed->name (), 'website' => $feed->website (), 'description' => $feed->description (), + 'lastUpdate' => $update ); $feedDAO->addFeed ($values); } diff --git a/app/models/Feed.php b/app/models/Feed.php index c88a4d527..2db9af40d 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -7,6 +7,7 @@ class Feed extends Model { private $name = ''; private $website = ''; private $description = ''; + private $lastUpdate = 0; public function __construct ($url) { $this->_url ($url); @@ -37,6 +38,9 @@ class Feed extends Model { public function description () { return $this->description; } + public function lastUpdate () { + return $this->lastUpdate; + } public function nbEntries () { $feedDAO = new FeedDAO (); return $feedDAO->countEntries ($this->id ()); @@ -74,6 +78,9 @@ class Feed extends Model { } $this->description = $value; } + public function _lastUpdate ($value) { + $this->lastUpdate = $value; + } public function load () { if (!is_null ($this->url)) { @@ -130,7 +137,7 @@ class Feed extends Model { class FeedDAO extends Model_pdo { public function addFeed ($valuesTmp) { - $sql = 'INSERT INTO feed (id, url, category, name, website, description) VALUES(?, ?, ?, ?, ?, ?)'; + $sql = 'INSERT INTO feed (id, url, category, name, website, description, lastUpdate) VALUES(?, ?, ?, ?, ?, ?, ?)'; $stm = $this->bd->prepare ($sql); $values = array ( @@ -140,6 +147,7 @@ class FeedDAO extends Model_pdo { $valuesTmp['name'], $valuesTmp['website'], $valuesTmp['description'], + $valuesTmp['lastUpdate'], ); if ($stm && $stm->execute ($values)) { @@ -171,6 +179,22 @@ class FeedDAO extends Model_pdo { } } + public function updateLastUpdate ($id) { + $sql = 'UPDATE feed SET lastUpdate=? WHERE id=?'; + $stm = $this->bd->prepare ($sql); + + $values = array ( + time (), + $id + ); + + if ($stm && $stm->execute ($values)) { + return true; + } else { + return false; + } + } + public function deleteFeed ($id) { $sql = 'DELETE FROM feed WHERE id=?'; $stm = $this->bd->prepare ($sql); @@ -209,6 +233,14 @@ class FeedDAO extends Model_pdo { return HelperFeed::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC)); } + public function listFeedsOrderUpdate () { + $sql = 'SELECT * FROM feed ORDER BY lastUpdate'; + $stm = $this->bd->prepare ($sql); + $stm->execute (); + + return HelperFeed::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC)); + } + public function listByCategory ($cat) { $sql = 'SELECT * FROM feed WHERE category=? ORDER BY name'; $stm = $this->bd->prepare ($sql); @@ -254,6 +286,7 @@ class HelperFeed { $list[$key]->_name ($dao['name']); $list[$key]->_website ($dao['website']); $list[$key]->_description ($dao['description']); + $list[$key]->_lastUpdate ($dao['lastUpdate']); } return $list; diff --git a/app/views/javascript/main.phtml b/app/views/javascript/main.phtml index a9ce2c5b1..1fb30feb1 100644 --- a/app/views/javascript/main.phtml +++ b/app/views/javascript/main.phtml @@ -21,15 +21,15 @@ function slide (new_active, old_active) { new_active.addClass ("active"); if (hide_posts) { - old_active.children (".content").slideUp (200); - new_active.children (".content").slideDown (200, function () { + old_active.children (".content").slideUp (500); + new_active.children (".content").slideDown (500, function () { $.smoothScroll({ - offset: new_active.position ().top + offset: new_active.position ().top - 50 }); }); } else { $.smoothScroll({ - offset: new_active.position ().top + 25 + offset: new_active.position ().top - 50 }); } } diff --git a/public/theme/base.css b/public/theme/base.css index bf19ef0ae..9a0cce46d 100644 --- a/public/theme/base.css +++ b/public/theme/base.css @@ -184,6 +184,7 @@ form { } #main_aside { position: fixed; + z-index: 10; } #categories { height: 69%; @@ -200,11 +201,14 @@ form { vertical-align: top; } #top { - width: 100%; + position: fixed; + top: 0; + width: 85%; background: #eee; border-bottom: 1px solid #aaa; box-shadow: 0 1px 3px #aaa; text-align: center; + z-index: 0; } #top a { display: inline-block; @@ -218,7 +222,7 @@ form { text-decoration: none; } #stream { - padding: 0; + padding: 50px 0 0; } #main .table { display: table; |
