T
T
Tokenchik2017-04-20 11:31:17
Yii
Tokenchik, 2017-04-20 11:31:17

How to reduce the number of requests per page?

I display products on the site page, for each product a picture is displayed. Work with images goes through the popular CostaRico plugin. In view, as usual, I pass the received data on the product through compact and display it in foreach. But at each iteration, you have to access the database for searching using the getImage () method.
Thus, in addition to the request for 16 products, 16 more are made to receive a picture for each product.
Can anyone work with this plugin and can tell you how to do it right? Or is 20 requests per page the norm?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Maxim Timofeev, 2017-04-20
@Tokenchik

via the popular CostaRico plugin

Where is popular? In Costa Rica? At least give a link to understand what I'm talking about.
It's not like usual, why compact? Show the code.
If getImage() contains a link, then you need to hook it with eager loading, something like this:
Then there will be 1 request for all images. The result will be 2 requests. 1 products and 1 all images for them.

B
Boris Yakushev, 2017-04-20
@za4me

Is the picture stored separately from the product?
Get all the necessary pictures with one request, what's the problem?

V
Valery, 2017-04-20
@Akuma

I do not work with Yii, but the image storage scheme is the same.
If a cache is used, then such a scheme perfectly keeps 4000 users a day and does not even think about stumbling.
Without a cache, of course, it's a little worse, but still, selecting images by index is a fairly simple matter.
If you are very worried, then you can select pictures in advance with one request, as suggested above. But in practice, this will justify itself either if you have a very weak server, or if there are a lot of users.

E
Evgeny Svirsky, 2017-04-20
@e_svirsky

Collect id-shniki and pull out all the images with one request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question