<p>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.</p>

<p>That means: each page with lots of thumbnails should be cached. :(</p>

CC BY-SA 3.0
2014-10-16T14:09:44.873Z
I thought so as well. Just wanted to check and see if there was any good workaround for it :)
naboovalley
CC BY-SA 3.0
2014-10-16T11:46:23.207Z
2014-10-16T11:46:23.207Z
carlcs
<p>I have a list of entries with a thumbnail (Image Asset) added to the entry. Within my <em>entries</em> loop I check if there's any image (thumbnail) added for the entry.</p>

<pre><code>{% set thumbnail = entry.thumbnail.first() %}
</code></pre>

<p>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.</p>

<p>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?</p>

CC BY-SA 3.0
2014-10-15T20:45:23.950Z
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.
Douglas McDonald
<entries><assets>
Optimize queries with list of image thumbnails
# Optimize queries with list of image thumbnails

(Asked by: username_0 on 2014-10-15)

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?

**Tags:** entries, assets
> **Comments:**
> **username_1**: 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.  

---

## 1 answers

### Answer by username_2 on 2014-10-16. Score: 1 | Accepted answer

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. :(

> **Comments:**
> **username_0**: I thought so as well. Just wanted to check and see if there was any good workaround for it :)  

---

