S
S
semki0962017-06-21 11:51:15
PHP
semki096, 2017-06-21 11:51:15

How to optimize database queries in Drupal8 on the example of a user profile?

Drupal8. I display only the avatar in the user profile. Or I display in the user's profile all his data. Question 1 - will the number of requests to the database be the same?
Question 2. Drupal uses the Twig template engine. If I want to put an avatar in my profile in the left bar - how best to do it Optimal? That is, either hook_preprocess, or display a view, which probably means requests to the database. What is the best? Maybe there is another option (without js).
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
afi13, 2017-06-22
@semki096

Drupal8. I display only the avatar in the user profile. Or I display in the user's profile all his data. Question 1 - will the number of requests to the database be the same?

The current user object will be loaded completely from the database, because it is used for more than just output. The number of queries to the database will be the same. But this is not critical, because. the object will be cached.
The question is too broad, the avatar can be displayed in many ways. You can make a custom block, use Views (in both cases, the block can be cached). Use Panels, or the standard Drupal templating system, etc.
The request to the database to receive the current user object when displaying the avatar will be in any case.
Keep in mind that all objects previously loaded during the execution of the request fall into the static cache and are not re-loaded from the database when they are called elsewhere.
In addition, you can write your own query and get only the field you need from the database, but I believe that in this case you will not gain anything in terms of performance.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question