Make WordPress Core

Opened 10 years ago

Last modified 5 years ago

#25787 new enhancement

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:

Description

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 (9)

#2 @wonderboymusic
10 years ago

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

@MisdaX
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

@MisdaX
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

Note: See TracTickets for help on using tickets.