Make WordPress Core

Opened 11 years ago

Closed 3 months ago

#25787 closed enhancement (wontfix)

wp_page_menu function is very inefficient

Reported by: whawker's profile whawker Owned by:
Milestone: Priority: normal
Severity: major Version: 3.7.1
Component: Posts, Post Types Keywords: has-patch needs-testing
Focuses: template, performance Cc:


I use wp_page_menu() to build my site's primary menu.

The MySQL query this creates, selects all the columns from the wp_posts table.

One of these columns is post_content. This means that when I create a menu, I am pulling massive amounts of data (the body text) from the DB which I will never (or very unlikely to) use. This adds a massive overhead which is killing my bandwidth.

Through my own investigations I have found that a menu can be built using only these columns from wp_posts

ID, menu_order, post_title, post_name, post_parent, post_type

This is much more efficient, but I do not feel I know the WordPress code base well enough to contribute to the core.

Attachments (2)

25787.diff (16.1 KB) - added by MisdaX 9 years ago.
first attempt without breaking existing functionality
25787-2-fixed-formatting-and-comments.diff (16.1 KB) - added by MisdaX 9 years ago.
fixed some issues with formatting and comments -> replaces first attempt

Download all attachments as: .zip

Change History (10)

#2 @wonderboymusic
10 years ago

  • Focuses performance added
  • Keywords 2nd-opinion dev-feedback removed
  • Milestone changed from Awaiting Review to Future Release

9 years ago

first attempt without breaking existing functionality

#3 @MisdaX
9 years ago

I tried to extend the core functions without breaking the current functionality.

  • wp_page_menu() has a new argument "optimize_query" which is delegated to wp_list_pages()
  • wp_list_pages() has a new argument "optimize_query" which defines a minimum set of wp_posts columns (for get_pages()) to serve the function (if true)
  • get_pages() has a new argument "restrict_columns" which restricts the number of of fetched columns from the database (if not empty)

Profiling with xdebug shows faster execution time and a dump of memory_get_peak_usage() shows lower memory consumption on my installation.

#4 @SergeyBiryukov
9 years ago

  • Component changed from Menus to Posts, Post Types
  • Focuses template added

9 years ago

fixed some issues with formatting and comments -> replaces first attempt

#5 @MisdaX
9 years ago

  • Keywords has-patch added; needs-patch removed

#6 @MisdaX
9 years ago

  • Keywords needs-testing added

This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.

8 years ago

#8 @pbearne
3 months ago

  • Resolution set to wontfix
  • Status changed from new to closed

get_post now uses wp_query so this approach doesn't work so closing as won't fix

Note: See TracTickets for help on using tickets.