S
S
Sergey2015-10-21 14:41:45
Yii
Sergey, 2015-10-21 14:41:45

How to properly use the Query Query Builder in Yii2?

Rewrote the project from yii1 to yii2, brakes appeared. The heaviest page used to load 0.5-0.8 seconds. now the same page 5.8 sec. 1700 requests to the database are used, which takes 280 ms. I can not understand what the rest of the time is spent on. I don't use ActiveRecord, I use only the query builder.
In yii1 I accessed the database like this:

$command = Yii::app()->db->createCommand();
$command->from('user');
$result = $command->queryAll();

On yii2, I also rewrote the same to:
$query = new Query();
$query->from('user');
$result = $query->all();

I suspected that the brakes could come from creating a huge number of instances of the Query class, because the site uses a lot of recursive queries.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Khomenko, 2015-10-21
@iiifx

Open Debug framework, find duplicate requests. Find out where they are made. Optimize the work so that the data from the database is reused, and not requested every time
With suspicion, you need to go to a fortune teller. Make debugging, determine what, where and how slows down and fix it.

A
Andrew, 2015-10-21
@R0dger

Why not make a model and make requests from it already?
and already use recursion as described in the documentation. After all not always the data is necessary for you on this recursion.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question