diff --git a/web/yaamp/core/functions/memcache.php b/web/yaamp/core/functions/memcache.php index 611e628..ff775b0 100644 --- a/web/yaamp/core/functions/memcache.php +++ b/web/yaamp/core/functions/memcache.php @@ -15,51 +15,60 @@ class YaampMemcache return memcache_get($this->memcache, $key); } - public function set($key, $value, $t=30) + public function set($key, $value, $t=30, $options=0) { - memcache_set($this->memcache, $key, $value, 0, $t); + memcache_set($this->memcache, $key, $value, $options, $t); } //////////////////////////////////////////////////////////////// - public function get_database_count($key, $query, $params=array()) - { - - } - - public function get_database_scalar($key, $query, $params=array()) + public function get_database_scalar($key, $query, $params=array(), $t=30) { $value = $this->get($key); - if($value === false) - { + if($value === false) { $value = dboscalar($query, $params); - $this->set($key, $value); + $this->set($key, $value, $t); } - return $value; } - public function get_database_count_ex($key, $table, $query, $params=array()) + public function get_database_column($key, $query, $params=array(), $t=30) { $value = $this->get($key); - if($value === false) - { + if($value === false) { + $value = dbocolumn($query, $params); + $this->set($key, $value, $t); + } + return $value; + } + + public function get_database_count_ex($key, $table, $query, $params=array(), $t=30) + { + $value = $this->get($key); + if($value === false) { $value = getdbocount($table, $query, $params); - $this->set($key, $value); + $this->set($key, $value, $t); } - return $value; } - public function get_database_row($key, $query, $params=array()) + public function get_database_list($key, $query, $params=array(), $t=30) { $value = $this->get($key); - if($value === false) - { - $value = dborow($query, $params); - $this->set($key, $value); + if($value === false) { + $value = dbolist($query, $params); + $this->set($key, $value, $t, MEMCACHE_COMPRESSED); } + return $value; + } + public function get_database_row($key, $query, $params=array(), $t=30) + { + $value = $this->get($key); + if($value === false) { + $value = dborow($query, $params); + $this->set($key, $value, $t); + } return $value; } @@ -78,8 +87,6 @@ class YaampMemcache $a[$name] = $count+1; memcache_set($this->memcache, 'url-map', $a); } -}; - - +} diff --git a/web/yaamp/modules/bench/devices.php b/web/yaamp/modules/bench/devices.php index 4ddf8e0..5bc76d3 100644 --- a/web/yaamp/modules/bench/devices.php +++ b/web/yaamp/modules/bench/devices.php @@ -2,10 +2,21 @@ include('functions.php'); +$client_ip = arraySafeVal($_SERVER,'REMOTE_ADDR'); +$whitelisted = isAdminIP($client_ip); +if (!$whitelisted && is_file(YAAMP_LOGS.'/overloaded')) { + header('HTTP/1.0 503 Disabled, server overloaded'); + return; +} + $this->pageTitle = "Devices"; $chips = array(); -$in_db = dbolist("SELECT DISTINCT device, type, chip, idchip, vendorid FROM benchmarks WHERE idchip > 0 ORDER BY type DESC, device, vendorid"); +// todo: bench_devices table to cache that +$in_db = $this->memcache->get_database_list("benchmarks-devices", + "SELECT DISTINCT device, type, chip, idchip, vendorid FROM benchmarks WHERE idchip > 0 ORDER BY type DESC, device, vendorid", + array(), 120 +); foreach ($in_db as $key => $row) { $vendorid = $row['vendorid']; $chip = $row['chip']; @@ -42,7 +53,12 @@ Devices in database end; $algos_columns = ''; -$algos = dbocolumn("SELECT DISTINCT algo FROM benchmarks ORDER BY algo LIMIT 30"); +$month = time() - (30 * 24 * 3600); + +$algos = $this->memcache->get_database_column("benchmarks-algos", + "SELECT DISTINCT algo FROM benchmarks WHERE time > $month ORDER BY algo LIMIT 20", + array(), 120 +); foreach ($algos as $algo) { $algos_columns .= ''.$algo.''; } @@ -101,9 +117,10 @@ foreach ($in_db as $row) { echo ''.CHtml::link($row['vendorid'],'/bench?vid='.$row['vendorid']).''; if (!empty($vendorid)) - $records = dbocolumn("SELECT algo FROM benchmarks WHERE vendorid=:vid ", array(':vid'=>$vendorid)); + $records = dbocolumn("SELECT DISTINCT algo FROM benchmarks WHERE vendorid=:vid ", array(':vid'=>$vendorid)); else - $records = dbocolumn("SELECT algo FROM benchmarks WHERE device=:dev ", array(':dev'=>$row['device'])); // cpu + $records = dbocolumn("SELECT DISTINCT algo FROM benchmarks WHERE device=:dev ", array(':dev'=>$row['device'])); // cpu + foreach ($algos as $algo) { $tick = ' '; if (in_array($algo, $records)) {