title: Using will_paginate without :total_entries to improve a lengthy query
body: <p>I have a current implementation of <strong>will_paginate</strong> that uses the <strong>paginate_by_sql</strong> method to build the collection to be paginated.  We have a custom query for <strong>total_entries</strong> that's very complicated and puts a large load on our DB.  Therefore we would like to cut total_entries from the pagination altogether.  </p>
  
  <p>In other words, instead of the typical pagination display of 'previous 1 [2] 3 4 5 next', we would simply like a 'next - previous' button only.  But we need to know a few things.</p>
  
  <ol>
  <li>Do we display the previous link?  This would only occur of course if records existing prior to the ones displayed in the current selection</li>
  <li>Do we display the next link?  This would not be displayed if the last record in the collection is being displayed</li>
  </ol>
  
  <p>From the <a href="http://gitrdoc.com/rdoc/mislav/will_paginate/b3b0f593ea9b1da13a64bc825dfe17b6bbc2828b/classes/WillPaginate/Finder/ClassMethods.html#M000140" rel="noreferrer">docs</a></p>
  
  <blockquote>
    <p>A query for counting rows will
    automatically be generated if you
    don’t supply :total_entries. If you
    experience problems with this
    generated SQL, you might want to
    perform the count manually in your
    application.</p>
  </blockquote>
  
  <p>So ultimately the ideal situation is the following.</p>
  
  <ul>
  <li>Remove the total_entries count because it's causing too much load on the database</li>
  <li>Display 50 records at a time with semi-pagination using only next/previous buttons to navigate and not needing to display all page numbers available</li>
  <li>Only display the next button and previous button accordingly</li>
  </ul>
  
  <p>Has anyone worked with a similar issue or have thoughts on a resolution?</p>