Jump to content

Speed, using find vs children methods


muzzer
 Share

Recommended Posts

I just had a duh! moment and thought I should share as it may be useful to others, especially PW beginners. I know a lot of you will go "yeah well duh...." and yeah, well I feel like a bit of an idiot but anyways....

I had a page outputting a table detailing data from about 200 records (PW pages). For each record it searched for child pages of a certain template, probably averaging 3 child pages per record and added some data from those pages to each row of the table. Simple stuff.

The page was averaging about 12 seconds to load. Anyway, today I got frustrated enough to try to work out why it was so slow. Turns out I realised that the child pages I was searching for were all direct children, so I changed my search method from

$pages->get(....)->find(.....) 

to

$pages->get(.....)->children(.....)

and blow me down the page load has gone from 12 seconds to a tad over 1 second. Turns out each child page had many child pages of their own (thousand of pages in total) and all these were being searched with the find() method. Stupid mistake, but I think right from the beginning of my learning of PW the find() method was ingrained.

So hopefully this helps some newbies and others like me. Check out

http://cheatsheet.processwire.com/page/built-in-methods-reference/page-find-selector/

and 

http://cheatsheet.processwire.com/page/built-in-methods-reference/page-children-selector/

for more info on these methods and others.

 

 

  • Like 13
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

×
×
  • Create New...