Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-16T14:09:44.873Z
Answers.Text: I thought so as well. Just wanted to check and see if there was any good workaround for it :)
Answers.UserDisplayName: naboovalley
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-16T11:46:23.207Z
Answers.LastActivityDate: 2014-10-16T11:46:23.207Z
Answers.UserDisplayName: carlcs
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-15T20:45:23.950Z
Comments.Text: 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.
Comments.UserDisplayName: Douglas McDonald
Tags: <entries><assets>
Title: Optimize queries with list of image thumbnails
ThreadText: # 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 :)  
  
  ---
  
  