title: AQL Optimization - traversal by month
body: <p>In ArangoDB, I have a graph which contains messages for profiles. For reporting purposes, I need to aggregate the number of messages for specific categories of message from each month for the last 12 months.</p>
  
  <p>The date and category of each message are on every edge between the profile and the message.</p>
  
  <p>Currently, I have:</p>
  
  <pre><code>for mo in 0..11
      let month = DATE_MONTH(DATE_SUBTRACT(DATE_NOW(),mo,"month"))
      let msgCount = count(
          for v, e in outbound "profileId" graph 'MyGraph'
              filter e.category == "myCategory" &amp;&amp; DATE_MONTH(e.date) == month
              return 1
          )
      return {month: month, msgCount: msgCount}
  </code></pre>
  
  <p>This query executes in over one second, which is a bit slow for the purposes of this webapp, as I need to create and visualize this report for several categories.</p>
  
  <p>Is there any optimization that could produce the same results faster? </p>