Performance issue #15915
Replies: 5 comments
-
I've just updated to the recent version of php 7.4.28 and phalcon 4.1.2 and it's all the same. |
Beta Was this translation helpful? Give feedback.
-
@Krzysiaczek Please provide detailed code and logs. And thanks for report! UPD. Right now phalcon orm doesn't provides eager loading features. You can look for |
Beta Was this translation helpful? Give feedback.
-
The code inside the method
and here is the problem that this way what is returned is the Phalcon\Mvc\Model\Resultset\Simple object which is not a data but the object which executes the query again when is called from the view. I figured out that this could be easily fixed by adding Instead you can read things like this ...
After reading that it's clear that $records variable should hold the results of the executed query. Instead if you pass $records to a view and run |
Beta Was this translation helpful? Give feedback.
-
This is related to lazy loading behavior of Active Record paradigm, which is Phalcon ORM itself. As i mentioned before, you can look for eager loading libraries to wrap queries. This will allow you to cut of subrequests and boost request time perfomance, but you will pay with proccess memory consumption raise. |
Beta Was this translation helpful? Give feedback.
-
You can always introduce caching in your method. Something like this: public function getAvailableCategories(... same variables ...)
{
$key = sha1($variables); // you can calculate that
if (true !== isset($this->cacheMap[$key]) {
// prepare some dynamic $params
$phql = "SELECT c.category_id, c.name, count(DISTINCT(".$count_by.".activity_id)) as how_many, c.home_page
FROM App\Models\Categories c .... etc "
$this->cacheMap[$key] = $this->modelsManager->executeQuery($phql, $params);
}
return $this->cacheMap[$key];
} This will cache this result during this request, so you will not get duplicate queries. Alternatively you can make use of relationships in your models and use the |
Beta Was this translation helpful? Give feedback.
-
Hi
I've picked up Phalcon because of the best declared performance. I was trying to analyse my application and discovered something really weird. I am using version 4.1.0.
Please advise if I am doing something wrong in here or is it a bug in Phalcon - as it's what it seems to me.
In the controller I prepare (a vary standard way I guess) a variable for a view taken from the DB request (by PHQL in Model->Categories->getAvailableCategories()). This query is not very well optimised yet, so it returns the results in 60 msec right now.
The problem I discovered is that when I run a loop in the phtml view I get another 60 msec to get content for the $availableCategores variable
It takes another 60 msec to get this line in a view and I can see in the DB logs that this underlying query has been executed twice.
This sound like a bug to me.
I do not see anything in documentation to use a data prepared and collected already in the variable inside the controller. This make preparation of any data in a controller pointless if queries need to run again when requested from a view. It simply doubles the whole execution time.
Beta Was this translation helpful? Give feedback.
All reactions