Skip to content

Commit

Permalink
ServerController - cached osimages
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Feb 22, 2016
1 parent ab34d4a commit 12b0733
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
43 changes: 29 additions & 14 deletions src/controllers/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use hipanel\actions\ViewAction;
use hipanel\base\CrudController;
use hipanel\models\Ref;
use hipanel\modules\finance\controllers\TariffController;
use hipanel\modules\finance\models\Tariff;
use hipanel\modules\server\models\Osimage;
use hipanel\modules\server\models\Server;
Expand Down Expand Up @@ -49,7 +48,12 @@ public function actions()
],
'view' => [
'class' => ViewAction::class,
'findOptions' => ['with_requests' => true, 'show_deleted' => true, 'with_discounts' => true],
'findOptions' => [
'with_requests' => true,
'show_deleted' => true,
'with_discounts' => true,
'with_uses' => true,
],
'data' => function ($action) {
/**
* @var $controller $this
Expand All @@ -60,12 +64,15 @@ public function actions()
$model->vnc = $controller->getVNCInfo($model);

$panels = $controller->getPanelTypes();
$tariff = Tariff::find()->where([
'id' => $model->tariff_id,
'show_final' => true,
'show_deleted' => true,
'with_resources' => true,
])->joinWith('resources')->one();

$tariff = Yii::$app->cache->getAuthTimeCached(3600, [$model->tariff_id], function ($tariff_id) {
return Tariff::find()->where([
'id' => $tariff_id,
'show_final' => true,
'show_deleted' => true,
'with_resources' => true,
])->joinWith('resources')->one();
});

$ispSupported = false;
if ($tariff !== null) {
Expand Down Expand Up @@ -251,20 +258,28 @@ protected function getOsimages(Server $model = null)
$condition['type'] = $model->type;
}

if (($models = Osimage::find()->where($condition)->all()) !== null) {
$models = Yii::$app->cache->getTimeCached(3600, [$condition], function ($condition) {
return Osimage::find()->where($condition)->all();
});

if ($models !== null) {
return $models;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}

throw new NotFoundHttpException('The requested page does not exist.');
}

protected function getOsimagesLiveCd()
{
if (($models = Osimage::findAll(['livecd' => true])) !== null) {
$models = Yii::$app->cache->getTimeCached(3600, [true], function ($livecd) {
return Osimage::findAll(['livecd' => $livecd]);
});

if ($models !== null) {
return $models;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}

throw new NotFoundHttpException('The requested page does not exist.');
}

protected function getPanelTypes()
Expand Down
2 changes: 1 addition & 1 deletion src/views/server/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
echo $box->renderTitle(Yii::t('hipanel/server', 'Resources consumption'));
$box->endHeader();
$box->beginBody();
echo 'yo';

$box->endBody();
$box->end();
?>
Expand Down

0 comments on commit 12b0733

Please sign in to comment.