Added caching of the database, attachments and uploaded files to avoid calculating them each time.
This commit is contained in:
parent
a91ce1600f
commit
c534894995
@ -366,12 +366,12 @@ class IDF_Project extends Pluf_Model
|
|||||||
public function getRepositorySize($force=false)
|
public function getRepositorySize($force=false)
|
||||||
{
|
{
|
||||||
$last_eval = $this->getConf()->getVal('repository_size_check_date', 0);
|
$last_eval = $this->getConf()->getVal('repository_size_check_date', 0);
|
||||||
if (!$force and $last_eval > time()-86400) {
|
if (!$force and $last_eval > time()-172800) {
|
||||||
return $this->getConf()->getVal('repository_size', -1);
|
return $this->getConf()->getVal('repository_size', -1);
|
||||||
}
|
}
|
||||||
|
$this->getConf()->setVal('repository_size_check_date', time());
|
||||||
$scm = IDF_Scm::get($this);
|
$scm = IDF_Scm::get($this);
|
||||||
$this->getConf()->setVal('repository_size', $scm->getRepositorySize());
|
$this->getConf()->setVal('repository_size', $scm->getRepositorySize());
|
||||||
$this->getConf()->setVal('repository_size_check_date', time());
|
|
||||||
return $this->getConf()->getVal('repository_size', -1);
|
return $this->getConf()->getVal('repository_size', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,25 +344,48 @@ function IDF_Views_Admin_projectSize($field, $project)
|
|||||||
*
|
*
|
||||||
* @return array Associative array with the size of each element
|
* @return array Associative array with the size of each element
|
||||||
*/
|
*/
|
||||||
function IDF_Views_Admin_getForgeSize()
|
function IDF_Views_Admin_getForgeSize($force=false)
|
||||||
{
|
{
|
||||||
|
$conf = new IDF_Gconf();
|
||||||
|
$conf->setModel((object) array('_model'=>'IDF_Forge', 'id'=> 1));
|
||||||
$res = array();
|
$res = array();
|
||||||
$res['repositories'] = 0;
|
$res['repositories'] = 0;
|
||||||
foreach (Pluf::factory('IDF_Project')->getList() as $prj) {
|
foreach (Pluf::factory('IDF_Project')->getList() as $prj) {
|
||||||
$size = $prj->getRepositorySize();
|
$size = $prj->getRepositorySize($force);
|
||||||
if ($size != -1) {
|
if ($size != -1) {
|
||||||
$res['repositories'] += $size;
|
$res['repositories'] += $size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$cmd = Pluf::f('idf_exec_cmd_prefix', '').'du -sk '
|
$last_eval = $conf->getVal('downloads_size_check_date', 0);
|
||||||
.escapeshellarg(Pluf::f('upload_path'));
|
if (!$force and $last_eval > time()-172800) {
|
||||||
$out = explode(' ', shell_exec($cmd), 2);
|
$res['downloads'] = $conf->getVal('downloads_size', 0);
|
||||||
$res['downloads'] = $out[0]*1024;
|
} else {
|
||||||
$cmd = Pluf::f('idf_exec_cmd_prefix', '').'du -sk '
|
$conf->setVal('downloads_size_check_date', time());
|
||||||
.escapeshellarg(Pluf::f('upload_issue_path'));
|
$cmd = Pluf::f('idf_exec_cmd_prefix', '').'du -sk '
|
||||||
$out = explode(' ', shell_exec($cmd), 2);
|
.escapeshellarg(Pluf::f('upload_path'));
|
||||||
$res['attachments'] = $out[0]*1024;
|
$out = explode(' ', shell_exec($cmd), 2);
|
||||||
$res['database'] = IDF_Views_Admin_getForgeDbSize();
|
$res['downloads'] = $out[0]*1024;
|
||||||
|
$conf->setVal('downloads_size', $res['downloads']);
|
||||||
|
}
|
||||||
|
$last_eval = $conf->getVal('attachments_size_check_date', 0);
|
||||||
|
if (!$force and $last_eval > time()-172800) {
|
||||||
|
$res['attachments'] = $conf->getVal('attachments_size', 0);
|
||||||
|
} else {
|
||||||
|
$conf->setVal('attachments_size_check_date', time());
|
||||||
|
$cmd = Pluf::f('idf_exec_cmd_prefix', '').'du -sk '
|
||||||
|
.escapeshellarg(Pluf::f('upload_path'));
|
||||||
|
$out = explode(' ', shell_exec($cmd), 2);
|
||||||
|
$res['attachments'] = $out[0]*1024;
|
||||||
|
$conf->setVal('attachments_size', $res['attachments']);
|
||||||
|
}
|
||||||
|
$last_eval = $conf->getVal('database_size_check_date', 0);
|
||||||
|
if (!$force and $last_eval > time()-172800) {
|
||||||
|
$res['database'] = $conf->getVal('database_size', 0);
|
||||||
|
} else {
|
||||||
|
$conf->setVal('database_size_check_date', time());
|
||||||
|
$res['database'] = IDF_Views_Admin_getForgeDbSize();
|
||||||
|
$conf->setVal('database_size', $res['database']);
|
||||||
|
}
|
||||||
$res['total'] = $res['repositories'] + $res['downloads'] + $res['attachments'] + $res['database'];
|
$res['total'] = $res['repositories'] + $res['downloads'] + $res['attachments'] + $res['database'];
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user