Wordpress - Extremely Slow on Large Site - get_page_children Function Responsible

drgdrg
drgdrg used Ask the Experts™
on
I'm converting a large information site from HTML to Wordpress.  There are over 10,000 pages of content.  On some themes the site crawls, on basic themes like TWENTY TWELVE it flies.

What I have isolated is a function function in post.php that is causing the slow down.  

/**

COMMENTED OUT BY ME

function get_page_children($page_id, $pages) {
     $page_list = array();
     foreach ( (array) $pages as $page ) {
          if ( $page->post_parent == $page_id ) {
               $page_list[] = $page;
               if ( $children = get_page_children($page->ID, $pages) )
                    $page_list = array_merge($page_list, $children);
          }
     }
     return $page_list;
}
*/

/**
Added by ME
*/

function get_page_children($page_id, $pages) {
     $page_list = array();
     return $page_list;
}

Open in new window


Basically, it seemed to be doing a tremendous number of recursive searches over 10,000+ pages looking for matches.

Is there a more efficient way to do this with a SQL query and, if yes, what would you do?

This has been a temporary fix.... the site is now flying.  The Parent / Child plugins we use do not make use of this function.

The only thing I've seen it break is:

http://www.XXXXXXXXXXXXXXX.com/wp-admin/edit.php?post_type=page

This would list all pages on the site that we could edit, albeit at 20 pages per screen.

Other than that, is this a problem?  Is there a better way to do it?  I know sites this size are unusual but should not be impossible.  

I know this is well established code in WP, but it cannot be the most efficient way of handling things when dealing with a large site.

Finally, is there any way for me to take whatever function is recommended and make it a child theme / function / something that "takes priority" over the one built into post.php?

I can edit post.php but if we do a WP update, it will wipe the change.  I'm wondering if you can have priority functions, the way you would take precedence in CSS.

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Don't talk to me.
Commented:
On some themes the site crawls, on basic themes like TWENTY TWELVE it flies.

I don't doubt this but the code you commented out is in the core.  If you see a difference between themes, it means that there is something in the loop call that is different between the two themes that is causing the site to slow down.

Is there a more efficient way to do this with a SQL query and, if yes, what would you do?

Potentially.  Is this problem on the backend or the front end?

 I know sites this size are unusual but should not be impossible.  

Are you sure the database server is robust enough to handle a table of this size?

whatever function is recommended and make it a child theme / function / something that "takes priority" over the one built into post.php

Depending on exactly how we solve this, it could be done with a hook.  Not sure which one at this time though.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial