S
S
seacjs2017-06-21 02:58:01
Yii
seacjs, 2017-06-21 02:58:01

Is it normal to have a large number of database queries in Yii2?

I'm doing a project in Yii2. Before that, I used QueryBuilder in projects, but now I decided to try ActiveQuery and it is not undoubtedly more convenient. But I noticed that on almost all pages there are a large number of calls to the database. (See screenshot)
Judging by the debugger, they do not take much time.
The news page displays categories of news, and a list of two news items. Plus pictures are uploaded.
f72d15d2200048e9bf2318c8a9c5c672.png
Tell me if this is normal for Yii2? Or it is necessary to optimize requests?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-06-21
@qonand

No, it's not normal. A large number of requests is bad and this behavior should be eliminated. Most likely you have a large number of queries due to the following reasons
1. Database schema caching is not enabled. Accordingly, you need to enable
it 2. Eager data loading is not used

M
Maxim Timofeev, 2017-06-21
@webinar

22 requests is nothing. But here the question is not in quantity as such, but in optimality. We need to see what these queries are and whether they can be reduced, combined, cached, etc.
Be sure to read this: www.yiiframework.com/wiki/834

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question