Solved

Wordpress - Extremely Slow on Large Site - get_page_children Function Responsible

Posted on 2012-12-28
1
816 Views
Last Modified: 2013-05-13
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!
0
Comment
Question by:drgdrg
1 Comment
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 38728735
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The viewer will learn how to count occurrences of each item in an array.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now