Hey guys!
So I am trying to understand my performance.
I have a application built on INVO, phalcon 3.4.7. Empty controller, only in BaseController I call a user object.
Thing is DESCRIBE QUERY is called, even when the object is cached. And it is a majority of my loading time. I dont understand why. Whats the point of cache if 90% of the load (Describe) is still called? My understand is DESCRIBE is called because I call a user object. Can I optimize this in some way?
<?php
use Phalcon\Mvc\Controller;
use Phalcon\Mvc\View;
use Phalcon\Cache\Backend\File as BackFile;
use Phalcon\Cache\Frontend\Data as FrontData;
class ControllerBase extends Controller {
public $user;
protected function initialize() {
///////////////// TESTING!! //////////////////
require_once APP_PATH . 'vendor/autoload.php';
$profiler = new \Fabfuel\Prophiler\Profiler();
$profiler->addAggregator(new \Fabfuel\Prophiler\Aggregator\Database\QueryAggregator());
$profiler->addAggregator(new \Fabfuel\Prophiler\Aggregator\Cache\CacheAggregator());
$logger = new \Fabfuel\Prophiler\Adapter\Psr\Log\Logger($profiler);
$pluginManager = new \Fabfuel\Prophiler\Plugin\Manager\Phalcon($profiler);
$pluginManager->register();
///////////////// TESTING!! //////////////////
$this->view->setTemplateAfter('main');
if ($this->cookies->has('remember-me') AND is_null($this->session->get('auth'))) {
// Get the cookie
return $this->response->redirect('session/cookie_login');
}
else{
if(!is_null($this->session->get('auth'))){
$auth = $this->session->get('auth');
$id = $auth['id'];
$frontCache = new FrontData(
[
'lifetime' => 60, // Daily
]
);
if (file_exists('../app/cache/' . $id . '/') == false) {
mkdir('../app/cache/' . $id . '/', 0777, true);
}
$backend = new BackFile(
$frontCache,
[
'cacheDir' => '../app/cache/' . $id . '/',
]
);
$cache = new \Fabfuel\Prophiler\Decorator\Phalcon\Cache\BackendDecorator($backend, $profiler);
$cacheKey = $id . '_user.cache';
$results = $cache->get($cacheKey);
if ($results == null) {
$auth = $this->session->get('auth');
$user = Users::findFirstById($auth['id']);
if ($user) {
$results = $user;
$this->user = $results;
$this->view->setVar("auth_user", $this->user);
$cache->save($cacheKey, $results);
}
}
else{
$this->user = $results;
$this->view->setVar("auth_user", $this->user);
}
}
}
$toolbar = new \Fabfuel\Prophiler\Toolbar($profiler);
$toolbar->addDataCollector(new \Fabfuel\Prophiler\DataCollector\Request());
$this->view->setVar("profiler", $profiler);
$this->view->setVar("logger", $logger);
$this->view->setVar("toolbar", $toolbar);
}