I have a list of entries with a thumbnail (Image Asset) added to the entry. Within my entries loop I check if there's any image (thumbnail) added for the entry.

{% set thumbnail = entry.thumbnail.first() %}

Since each check requires one new query the queries keep adding up if the list has for example 100 entries. That's 100 queries just for displaying one thumbnail next to my entry.

Is there a better way of doing this? Could I for example get the URL to the image asset some other way then running a query on the AssetModel?

  • Wouldn't you retrieve the entry first and then check the found entry for a thumbnail image? Or are you trying to find all entries with thumbnails? Maybe if you share the whole loop code it will help clarify the question. Oct 15 '14 at 20:45

I think that's how it works and there's no way around this. That asset is related to your entry and to get the asset's URL property, Craft has to do a query to the database.

That means: each page with lots of thumbnails should be cached. :(

  • I thought so as well. Just wanted to check and see if there was any good workaround for it :) Oct 16 '14 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.