Solved

Wordpress - Extremely Slow on Large Site - get_page_children Function Responsible

Posted on 2012-12-28
1
835 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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 purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

628 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