evanmcd Posted July 30, 2012 Share Posted July 30, 2012 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 More sharing options...
Soma Posted July 30, 2012 Share Posted July 30, 2012 Maybe using ..."limit=5")->getTotal() ? Link to comment Share on other sites More sharing options...
ryan Posted July 30, 2012 Share Posted July 30, 2012 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 More sharing options...
Soma Posted July 30, 2012 Share Posted July 30, 2012 Yeah, I was faster and even right this time maybe! Link to comment Share on other sites More sharing options...
evanmcd Posted July 30, 2012 Author Share Posted July 30, 2012 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 More sharing options...
Martijn Geerts Posted July 30, 2012 Share Posted July 30, 2012 maybe you can check the memory: echo round(memory_get_peak_usage()/1024/1024, 2) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now