{"id":534,"date":"2009-09-24T00:14:22","date_gmt":"2009-09-23T22:14:22","guid":{"rendered":"http:\/\/patchlog.com\/?p=534"},"modified":"2009-09-24T00:14:22","modified_gmt":"2009-09-23T22:14:22","slug":"faster-wordpress-page-admin","status":"publish","type":"post","link":"https:\/\/patchlog.com\/wordpress\/faster-wordpress-page-admin\/","title":{"rendered":"Faster wordpress page admin"},"content":{"rendered":"<p>In a recent post about wordpress I explained how you can <a title=\"Fast page insert in wordpress\" href=\"http:\/\/patchlog.com\/wordpress\/fast-page-insert-in-wordpress\/\">create a lot of pages really fast<\/a>.\u00c2\u00a0 If that went well and you inserted a few thousand pages in your wordpress blog\u00c2\u00a0 the page admin became useless. Displaying the list of pages would take 3 minutes for 7000 pages on my test server.<\/p>\n<p>It seems this is not a new problem and there is a <a title=\"&quot;Manage &gt; Pages&quot; becomes very slow with hundreds of pages\" href=\"http:\/\/core.trac.wordpress.org\/ticket\/5303\">bug<\/a> created in 2007 about it. Although it seems like there was a patch to fix this, the problem still exists in the 2.8.4 version.<\/p>\n<h3>Why is this so slow ?<\/h3>\n<p>Short story: because wordpress is trying to display and sort pages hierarchically .<\/p>\n<p>At first I thought the problem was caused by the sql queries that fetched all the pages ( even though it doesn't display all of them on a page ) but that was not the case.<\/p>\n<p>After profiling the code with<a href=\"http:\/\/xdebug.org\"> xdebug<\/a> and <a href=\"http:\/\/kcachegrind.sourceforge.net\">Kcachegrind<\/a> I found there were a few parts of the code that were taking the longest time to complete.<\/p>\n<p>The main problem is that wordpress is trying to find the children for all the pages in an inefficient way. There is this function get_page_children in wp-includes\/post.php\u00c2\u00a0 which was taking about 2 thirds of the total time to complete ( ~ 2 minutes on my example\u00c2\u00a0 ).<\/p>\n<h3>The Solution<\/h3>\n<p>I rewrote that function to make it a lot more efficient. In my case it reduced the time from 2 minute to 1-2 seconds but on other page hierarchy it might take more, the worst case being when every page is the parent of another page.\u00c2\u00a0 The diff is here : [download id=\"15\"]<\/p>\n<p>The second problem is that wordpress updates the page cache every time you list pages. This was taking almost 1 minute to complete. I'm not sure if it's the right thing to just remove that call to update_page_cache in wp-includes\/post.php get_pages , but doing that made the page admin load in about 15 seconds.<\/p>\n<p>Now this might still be annoying but it's way better then 3 minutes. Hopefully at least the new get_page_children function will b included in the next wordpress release... maybe you can help promote <a title=\"&quot;Manage &gt; Pages&quot; becomes very slow with hundreds of pages\" href=\"http:\/\/core.trac.wordpress.org\/ticket\/5303\">this ticket<\/a> by giving it a positive vote although I'm not sure if those votes actually have any influence.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a recent post about wordpress I explained how you can create a lot of pages really fast.\u00c2\u00a0 If that went well and you inserted a few thousand pages in your wordpress blog\u00c2\u00a0 the page admin became useless. Displaying the list of pages would take 3 minutes for 7000 pages on my test server. It &hellip; <a href=\"https:\/\/patchlog.com\/wordpress\/faster-wordpress-page-admin\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Faster wordpress page admin<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[12],"tags":[134,284,285,283,94,359],"class_list":["post-534","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-admin","tag-fast","tag-fix","tag-page","tag-patch","tag-wordpress"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pofPh-8C","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/posts\/534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/comments?post=534"}],"version-history":[{"count":4,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/posts\/534\/revisions"}],"predecessor-version":[{"id":538,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/posts\/534\/revisions\/538"}],"wp:attachment":[{"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/media?parent=534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/categories?post=534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/tags?post=534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}