T
T
Timur Khudiyev2017-08-25 12:01:36
Yii
Timur Khudiyev, 2017-08-25 12:01:36

What is the optimal number of database queries in yii2?

Good day. I practice in yii2 and set myself the task of writing an admin panel. Before that, I wrote small admin panels for myself in a procedural style without frameworks. I am using yii2-admin module and rbac for user roles. And I found that this very module makes about 35 requests to the database. This is not counting the fact that my methods also work with the database, but there are only 2-4 queries. In total, there are 40 queries to the database for one action. Tell me is it okay? Isn't it too much for a small level project? For understanding, I’ll tell you in general terms what the admin panel is in terms of functionality.
3 user roles.
Accordingly, the admin has all the authority to CRUD
Well, each user on the personal page displays records belonging to him.
Generally that anything such global from a DB does not last.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Fedorov, 2017-08-25
@qonand

What is the optimal number of database queries in yii2?

There is no answer to this question, it all depends on the project and its functionality, so no one will tell you a specific figure. The fewer requests, the better.
As far as I understand, for tables that store RBAC data, in this case, you need to enable their caching

M
Maxim Fedorov, 2017-08-25
@Maksclub

most likely there is a lazy load, you need a greedy one
https://habrahabr.ru/post/306248/

M
Maxim Timofeev, 2017-08-26
@webinar

What is the optimal number of database queries in yii2?
46
You ask: "why 46"? And I will answer: "and why not." Since you asked me to give you an unconditional number, let it be 46.
It's normal, because it's less than 46. But is it possible to reduce it? This is another question that psychics can answer, I can't do it without a code.
Now it's harder. You need to understand what a "small level project" is. Well, since we have already started talking about things that are not classified, let's agree. For a small project - 42. For a medium - 46, and for a large - 67. But this is only on condition that
nothing such global is pulled from the database
and if it stretches, then we introduce the "global pull coefficient" (KGT 0.3) . Total 46 * 0.3 = 13.8 queries in the database
PS: the limit on the number of queries for the project is stupid. Your task is to optimize the project. In the optimization process, you should also pay attention to the number of queries in the database. And here we should look at "can we make them more optimal, make their number smaller, etc.", and not adjust to some figure. After all, the task - "works fast", and not "creates less than 46 requests
" I once asked myself the same question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question