issue #0001796: dashboard cache added

This commit is contained in:
Michael RICOIS 2013-11-29 06:45:22 +00:00
parent 05c54cbf47
commit f968c9cb8c
2 changed files with 43 additions and 26 deletions

View File

@ -165,6 +165,9 @@ class ComptageController extends Zend_Controller_Action
'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,

View File

@ -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);
$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()
$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();
$comptage = $comptagesM->fetchAll($sql)->toArray();
if (count($comptage)>0){
$info['resultat'] = $comptage[0]['resultat'];
$info['uniteInsee'] = $comptage[0]['uniteInsee'];
$info['dateComptage'] = $comptage[0]['dateAjout'];
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