Answers.Body: <p>If you know which years should appear, and there are no breaks in the timeline, perhaps it would make more sense to do a simple numeric loop instead...</p>
  
  <pre><code>{% for year in (now.year)..2009 %}
      {{ year }}
  {% endfor %}
  </code></pre>
  
  <p>That will count backwards from the current year to 2009.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-04T05:58:07.727Z
Answers.Text: Or you could use the oldest entry's postDate with `{% set oldestEntry = craft.entries.section('posts').order( 'postDate asc' ).first() %}` then use `oldestEntry.postDate|date( 'Y' )` is place of 2009.
Answers.UserDisplayName: Luke Pearce
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-04T08:47:54.303Z
Answers.Text: NICE idea @Luke Pearce!
Answers.UserDisplayName: Matt P
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-04T14:53:21.453Z
Answers.Text: Great point @LukePearce! You could do the same to get the newest entry (in case it's not from the current year). So at most, you'd only be querying for 2 entries.
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-04T16:30:38.500Z
Answers.Text: Perfect, thank you Lindsey and @LukePearce !
Answers.UserDisplayName: Bryant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-04T03:27:57.373Z
Answers.LastActivityDate: 2016-07-04T03:27:57.373Z
Answers.UserDisplayName: Lindsey D
Body: <p>I seem to be having trouble with the performance of my site (on localhost) after including this object. Im using it to build a menu for an archive of the posts section which has about 2,500 entries inside of it. </p>
  
  <pre><code>{% set allEntries = craft.entries.section('posts').limit(null) %}
  
  {% for year, entriesInYear in allEntries | group("postDate.year") %}
      {{ year }}
  {% endfor %}
  </code></pre>
  
  <p>This fetch request spits out the following:</p>
  
  <blockquote>
    <p>2016 2015 2014 2013 2012 2011 2010 2009</p>
  </blockquote>
  
  <p>When I make this fetch request, my page is reload time is ~11s. If I comment out this request my page reload time is ~3s. </p>
  
  <p>Is there a more economical way to return the years associated with my posts?</p>
  
Tags: <templating><elementcriteriamodel><performance><limit>
Title: A more economical method of building an archive menu?
ThreadText: # A more economical method of building an archive menu?
  
  (Asked by: username_0 on 2016-07-03)
  
  I seem to be having trouble with the performance of my site (on localhost) after including this object. Im using it to build a menu for an archive of the posts section which has about 2,500 entries inside of it.
  
  ```
  {% set allEntries = craft.entries.section('posts').limit(null) %}
  
  {% for year, entriesInYear in allEntries | group("postDate.year") %}
      {{ year }}
  {% endfor %}
  
  ```
  
  This fetch request spits out the following:
  
  > 2016 2015 2014 2013 2012 2011 2010 2009
  
  When I make this fetch request, my page is reload time is ~11s. If I comment out this request my page reload time is ~3s.
  
  Is there a more economical way to return the years associated with my posts?
  
  **Tags:** templating, elementcriteriamodel, performance, limit
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-07-04. Score: 5 | Accepted answer
  
  If you know which years should appear, and there are no breaks in the timeline, perhaps it would make more sense to do a simple numeric loop instead...
  
  ```
  {% for year in (now.year)..2009 %}
      {{ year }}
  {% endfor %}
  
  ```
  
  That will count backwards from the current year to 2009.
  
  > **Comments:**
  > **username_2**: Or you could use the oldest entry's postDate with `{% set oldestEntry = craft.entries.section('posts').order( 'postDate asc' ).first() %}` then use `oldestEntry.postDate|date( 'Y' )` is place of 2009.  
  > **username_3**: NICE idea @username_2!  
  > **username_1**: Great point @username_2! You could do the same to get the newest entry (in case it's not from the current year). So at most, you'd only be querying for 2 entries.  
  > **username_0**: Perfect, thank you username_1 and @username_2 !  
  
  ---
  
  