From f968c9cb8cac7e8bbb50a8adcb850c44ff4f3eaf Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Fri, 29 Nov 2013 06:45:22 +0000 Subject: [PATCH] issue #0001796: dashboard cache added --- .../controllers/ComptageController.php | 5 +- .../controllers/DashboardController.php | 64 +++++++++++-------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/application/controllers/ComptageController.php b/application/controllers/ComptageController.php index aea1df50..1b3c17d6 100644 --- a/application/controllers/ComptageController.php +++ b/application/controllers/ComptageController.php @@ -164,7 +164,10 @@ class ComptageController extends Zend_Controller_Action 'error'=>0, 'msg'=> "Vos critères ont été sauvegardés sous la référence $ref", 'href' => $this->view->url(array('controller'=>'dashboard', 'action'=>'ciblage', 'id'=>$id)) - )); + )); + //cache remove + $cache = Zend_Cache::factory('Output','File',array(),array('cache_dir' => '../data/cache/')); + $cache->remove($user->username); } else { echo json_encode(array( 'error'=>1, diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index e77dfbb4..aa29d92b 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -18,41 +18,55 @@ class DashboardController extends Zend_Controller_Action $request = $this->getRequest(); $type = $request->getParam('type', null); $this->view->type = $type; - $criteresM = new Application_Model_CiblageCriteres(); - $sql = $criteresM->select() + + //cache data + $frontendOptions = array( + 'lifetime' => 86400, + 'automatic_serialization' => true + ); + + $backendOptions = array('cache_dir' => '../data/cache/'); + $cache = Zend_Cache::factory('Output','File',$frontendOptions,$backendOptions); + if(($results = $cache->load($user->username)) === false) { + $criteresM = new Application_Model_CiblageCriteres(); + $sql = $criteresM->select() ->from($criteresM, array('id', 'reference', 'dateAjout')) ->where("idClient = ?", $user->idClient) ->where("login = ?", $user->username) ->order('dateAjout DESC'); - //->limit(5); - $rows = $criteresM->fetchAll($sql); - - // - $results = array(); - $comptagesM = new Application_Model_CiblageComptages(); - foreach($rows->toArray() as $item) - { - $info = array( - 'id' => $item['id'], - 'reference' => $item['reference'], - 'dateCriteres' => $item['dateAjout'], - ); - //Recherche des comptages - $sql = $comptagesM->select() + $rows = $criteresM->fetchAll($sql); + + $results = array(); + $comptagesM = new Application_Model_CiblageComptages(); + foreach($rows->toArray() as $item) + { + $info = array( + 'id' => $item['id'], + 'reference' => $item['reference'], + 'dateCriteres' => $item['dateAjout'], + ); + //Recherche des comptages + $sql = $comptagesM->select() ->from($comptagesM, array('resultat', 'uniteInsee', "DATE_FORMAT(dateAjout, '%Y/%m/%d %H:%i:%s') as dateAjout")) ->where('idDefinition = ?', $item['id']) ->order('dateAjout DESC')->limit(1); - $comptage = $comptagesM->fetchAll($sql)->toArray(); - - if (count($comptage)>0){ - $info['resultat'] = $comptage[0]['resultat']; - $info['uniteInsee'] = $comptage[0]['uniteInsee']; - $info['dateComptage'] = $comptage[0]['dateAjout']; + $comptage = $comptagesM->fetchAll($sql)->toArray(); + + if (count($comptage)>0){ + $info['resultat'] = $comptage[0]['resultat']; + $info['uniteInsee'] = $comptage[0]['uniteInsee']; + $info['dateComptage'] = $comptage[0]['dateAjout']; + } + + $results[] = $info; + } + if (!empty($results)) { + $cache->save($results, $user->username); } - - $results[] = $info; } + // + //paginate results list