Jump to content

"Allowed memory size" issue when working with many large $pages calls


evanmcd
 Share

Recommended Posts

Hi,

I've got a PW site functioning as a contest administration interface in which each contest entry is a Page. I've just passed 10k entries, and am starting to see performance issues in a custom reporting page I built.

Here's how I get the first part of the data I need for the reporting page:

$totalUnpublished = $pages->find("template=entry,status=unpublished")->count();
$totalPublished = $pages->find("template=entry, parent!=/entries/rejected/")->count();
$totalRejected = $pages->find("template=entry,parent=/entries/rejected/,include=all")->count();

I can imagine these calls are using a lot of memory, so I checked into the memory_limit setting and it's set at the 5.3 default of 128M. I would have thought that would be enough, but... no.

Is there a way for me to lighten the load of the returned PageArrays to reduce memory usage?

Thanks.

Link to comment
Share on other sites

Those API calls are probably loading all 10k pages since you are doing the count after the query. Try changing it to this and it should fix everything:

$totalUnpublished = $pages->count("template=entry,status=unpublished"); 
$totalPublished = $pages->count("template=entry, parent!=/entries/rejected/"); 
$totalRejected = $pages->count("template=entry,parent=/entries/rejected/,include=all"); 

Another way you could do it would be this (though I prefer the way above):

$totalUnpublished = $pages->find("template=entry,status=unpublished, limit=2")->getTotal(); 
$totalPublished = $pages->find("template=entry, parent!=/entries/rejected/, limit=2")->getTotal(); 
$totalRejected = $pages->find("template=entry,parent=/entries/rejected/, include=all, limit=2")->getTotal(); 

Either of those examples were perform at the same speed (which should be very fast).

Link to comment
Share on other sites

Oh my gosh, that is exactly what I was hoping for! Thanks.

I was looking on the PW cheatsheet, but mistakenly focused on the $pages section not the PageArray / WireArray section where getTotal lives.

You guys are the best.

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...