On Mon, Dec 23, 2013 at 10:37 AM, Xander Guzman <[email protected]> wrote: > I'm using a custom Paginator Adapter which uses a service to request and > merge data from a solr index with database data. Solr returns to me the > total number of documents that matched the search. > > Here's the problem, further up in the call stack they're calling ->count() > before ->getItems() which is causing me problems since the count isn't > being set until getItems() is being called. I'd hate to have to make two > requests just to get the count, that seems very wasteful with a full on > HTTP request. > > Is there a way to make it so getItems() is called before count() for these > kinds of situations? Or, can anyone think of a reason why we shouldn't do > it in that order? I can't think of anything that would cause problems. If > people use getItems() to populate the count they're covered, if people make > a secondary call it's still covered.
Why not do a check in your count() method to see if the count is populated, and, if not, call getItems() (or the logic you normally call in getItems()) to fetch it? That way you can use a single call and cache the information. -- Matthew Weier O'Phinney Project Lead | [email protected] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc -- List: [email protected] Info: http://framework.zend.com/archives Unsubscribe: [email protected]
