1 |
38716
|
eri.katsar
|
<?php
|
2 |
|
|
require_once('./js/log4php/Logger.php');
|
3 |
|
|
require_once('./paths.php');
|
4 |
|
|
//require_once('./MYDB.php');
|
5 |
|
|
include_once('./MYDB.php');
|
6 |
|
|
//require_once('./controller.php');
|
7 |
|
|
|
8 |
|
|
class refreshEmpty{
|
9 |
|
|
private $log;
|
10 |
|
|
private $cache = null;
|
11 |
|
|
public function __construct(){
|
12 |
|
|
|
13 |
|
|
global $redis_host;
|
14 |
|
|
global $redis_port;
|
15 |
|
|
global $redis_scheme;
|
16 |
|
|
global $host;
|
17 |
|
|
|
18 |
|
|
$this->log = Logger::getLogger(__CLASS__);
|
19 |
|
|
Logger::configure('./js/log4php/log4php.xml');
|
20 |
|
|
|
21 |
|
|
if(class_exists("Predis\Client")){
|
22 |
|
|
|
23 |
|
|
try {
|
24 |
|
|
//todo changed timeout from 0 to -1
|
25 |
|
|
$this->cache = new Predis\Client(array("scheme" => $redis_scheme,"host" => $redis_host,"port" => $redis_port,"read_write_timeout" => -1));
|
26 |
|
|
$this->log->info("redis host: ".$redis_host." and redis port: ".$redis_port);
|
27 |
|
|
} catch(Exception $e) {
|
28 |
|
|
$this->log->error("Error connecting to Redis server: ".$e->getMessage());
|
29 |
|
|
$this->cache = null;
|
30 |
|
|
}
|
31 |
|
|
}
|
32 |
|
|
else{
|
33 |
|
|
$this->log->info("cache does not exist"); //predis
|
34 |
|
|
exit;
|
35 |
|
|
}
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
function refresh() {
|
40 |
|
|
if($this->cache != null){
|
41 |
|
|
$this->log->info("cache exists");
|
42 |
|
|
$database = new MYDB();
|
43 |
|
|
$database->doConnect($GLOBALS['schema_file']);
|
44 |
|
|
$keys = $this->cache->keys("*");
|
45 |
|
|
|
46 |
|
|
$this->log->info(" ******************REFRESHING CACHE*************************");
|
47 |
|
|
|
48 |
|
|
//TODO REFRESH CHARTS AND DATA
|
49 |
|
|
|
50 |
|
|
for($x=0;$x<count($keys);$x++) {
|
51 |
|
|
$this->log->info("Looking up for key: ".$keys[$x]);
|
52 |
|
|
|
53 |
|
|
if (strpos($keys[$x],'STATS')===false)
|
54 |
|
|
{
|
55 |
|
|
try
|
56 |
|
|
{
|
57 |
|
|
|
58 |
|
|
$query = $this->cache->hget($keys[$x],'query');
|
59 |
|
|
$persistent= $this->cache->hget($keys[$x],'persistent');
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
$res=$this->cache->hget($keys[$x],'results');
|
63 |
|
|
if($res==" "||$res=="\"\""||empty($res))
|
64 |
|
|
{
|
65 |
|
|
|
66 |
|
|
$this->log->info("empty result id : ".$keys[$x]);
|
67 |
|
|
|
68 |
|
|
$this->log->info("going to recalculate the results for query ".$query );
|
69 |
|
|
$fetchMode = $this->cache->hget($keys[$x], 'fetchMode');
|
70 |
|
|
if($fetchMode==null)
|
71 |
|
|
{ $fetchMode=3; }
|
72 |
|
|
$shadowResults =$this->cache->hget($keys[$x], 'shadow');
|
73 |
|
|
$shadowResults = $database->doQueryNoCache($query, $fetchMode);
|
74 |
|
|
$result = $this->cache->hget($keys[$x], 'results');
|
75 |
|
|
// $this->log->info("Currently stored results".$result );
|
76 |
|
|
$backup = $this->cache->hget($keys[$x], 'backup');
|
77 |
|
|
//$this->log->info("Currently stored backup".$backup);
|
78 |
|
|
|
79 |
|
|
if(json_encode($shadowResults))
|
80 |
|
|
{$shadowResults=json_encode($shadowResults);}
|
81 |
|
|
$this->cache->hmset($keys[$x],array("results" => $shadowResults, "query" =>$query,"persistent" => $persistent,"shadow" => $shadowResults, "fetchMode" => $fetchMode, "backup" => $backup));
|
82 |
|
|
|
83 |
|
|
//$this->log->info("Stored Entry : ");
|
84 |
|
|
//$this->log->info("Shadow ".$this->cache->hget($keys[$x],'results'));
|
85 |
|
|
}
|
86 |
|
|
}//catch
|
87 |
|
|
catch(Exception $e) {
|
88 |
|
|
$this->log->error('Error : '.$e->getMessage());
|
89 |
|
|
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
else
|
95 |
|
|
{
|
96 |
|
|
$this->log->info("Ignoring chart key: ".$keys[$x]);
|
97 |
|
|
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
// for eeach key loop
|
105 |
|
|
|
106 |
|
|
$database->doDisconnect();
|
107 |
|
|
|
108 |
|
|
} else {
|
109 |
|
|
$this->log->info("cache does not exist");
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
$rc = new refreshEmpty();
|
114 |
|
|
$rc->refresh();
|
115 |
|
|
|
116 |
|
|
?>
|