Solved

Wordpress - Extremely Slow on Large Site - get_page_children Function Responsible

Posted on 2012-12-28
1
811 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PHP loop not working 4 30
Wordpress Body Class 5 11
Help cleaning out CSS 2 26
Can't connect to my database 2 0
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The viewer will learn how to count occurrences of each item in an array.

706 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

20 Experts available now in Live!

Get 1:1 Help Now