S
S
Sergey Zhukov2015-11-05 21:09:14
symfony
Sergey Zhukov, 2015-11-05 21:09:14

Question about additional load on the server?

Gentlemen, I have an extension of nested sets, But this is not important. For example, when I request a train in search:

<?foreach($row->getImages()->all() as $image):?>
    <li class="<?if($row->getImages()->all()[0] == $image):?>active<?endif;?>"> blahblah</li>
//... и еще до кучи

if(end($row->getImages()->all()) == $image)) //...
 <?endforeach;?>

Is there a difference in load from if I first store the entire result:
$result = $row->getImages()->all() ;
And I will iterate over it and access it ( $result ). Will there be a significant(*) performance difference? Or don't care? How are you doing?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-11-05
Protko @Fesor

How are you doing?

I write load tests.
As for your question - as if to spit. You have already downloaded the entire collection, that is, it has already gone to the database and taken all the pictures. Another question is that if you need not all but only the first element (judging by the code), then you need to use first().
ps Where is twig? he has already solved all these tasks (like checking whether the element is the first one) and moreover, very efficiently.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question