Hi,
I am wondering, is there a way to count items in the DB without returning the results? I have a site that is going to have 10,00 pages and I want to count them all.
Using $pages->find(selector)->count; returns the results and I guess this is the same as count($pages->find()) just counting how many items are in the returned wire array. Not what I want. I want to count items without the overhead of getting all the data.
Thanks,
how to count items without getting the results.
Started by joshuag, Jun 29 2012 02:05 PM
4 replies to this topic
#2
Posted 29 June 2012 - 02:13 PM
Actually I think there is very little overhead of doing that, since PW doesn't load the data until it is used (or if you have autojoin set on your fields). And if you don't have to loop all those pages it will be breeze.
You can also do this:
$pages->find(selector, limit=2)->getTotal()
But I guess it does pretty much the same under the hood (not sure though) - removes the limit and counts it.
You can also do this:
$pages->find(selector, limit=2)->getTotal()
But I guess it does pretty much the same under the hood (not sure though) - removes the limit and counts it.
#3
Posted 29 June 2012 - 02:29 PM
Awesome. Ok, I didn't know that. I thought PW got everything when I asked for it. This is great news. Thanks.
#5
Posted 29 June 2012 - 04:19 PM
ahh, great, thanks Ryan... strange that I didn't know about that one.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













