Jump to content

too many pages...


Frank Vèssia
 Share

Recommended Posts

I'm trying to count the total page i have in one category but i get this error:

FATAL ERROR: ALLOWED MEMORY SIZE OF 67108864 BYTES EXHAUSTED (TRIED TO ALLOCATE 80 BYTES) IN /HOME/LIBROLO/PUBLIC_HTML/WIRE/CORE/PAGES.PHP ON LINE 290

this is my code

$total=$pages->get(1485)->find("template=libro"); echo $total->getTotal();

my total is almost 7000 pages. Till 4500 was fine, no error.

Link to comment
Share on other sites

In which case I'd use a normal database query - couldn't see any docs on the site after the briefest of searches, but this thread should help you out: http://processwire.com/talk/index.php/topic,23.0.html

Since $db is all set up and ready to go it's likely more efficient to do it this way.

Oh, but for total pages in a category that won't work will it? Erm... not sure how you'd do that - you'd need some sort of function to find all child categories and then use a query based on those IDs to count the child pages.

Sorry, not being too much help here ;)

Link to comment
Share on other sites

That's way too many pages to try and load in memory at once. I'm impressed you were able to load that many. :) When you start dealing with hundreds or thousands of pages, start using "limit=n" to paginate whether for output or not. How many pages you can load at once depends on how many fields are being auto-joined to it and how much memory you have available to PHP. Here's are two ways to achieve what you want below.

This one loads a max of 3 pages. In the first example, we specify "limit=2" because any limit above 1 triggers PW's pagination (making it include the total matches). So we take advantage of that to get the total:

$total = $pages->get(1485)->find("template=libro, limit=2")->getTotal(); 

This next example requires PW 2.1. We use a "has_parent=1485" in the selector, which is a way to tell PW that the matched pages have to have that parent somewhere in their ancestors . That's something that the first example is doing for you since you are already specifying the parent by calling the find() directly from page 1485.

$total = $pages->count("has_parent=1485, template=libro"); 
Link to comment
Share on other sites

You can use limit. As long as specify a limit greater than 1, PW will still count the pages even if it doesn't load them. When you call getTotal() it tells you the total number of matches as if there were no limit. It has to do this for pagination, but it's a trick that's handy to know about even when you don't need pagination.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...