Make WordPress Core

Opened 8 years ago

Last modified 5 years ago

#36891 new enhancement

Saving large menus is super slow

Reported by: pento's profile pento Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Menus Keywords:
Focuses: administration, performance Cc:


When saving menus, wp-admin/includes/nav-menu.php calls wp_update_nav_menu_item() for every menu item. This function call can take 0.1-0.4s, when multiplied by 50 (or more!) menu items, is a less than pleasant experience.

Because of the length of time this takes, it's also quite likely that an interrupted connection could cause the menu to be saved in a weird state.

Change History (3)

#1 @pento
8 years ago

I'm guessing the slow part is the number of queries. Bulking UPDATEs aren't possible, so the next option might be to investigate avoiding queries in the first place - if a menu item hasn't changed, it doesn't need to be updated.

#2 @dd32
8 years ago

if a menu item hasn't changed, it doesn't need to be updated.

If you chase it down the rabbit hole, it'll probably come to wp_insert_post() which runs regardless of if things have changed.
Bailing early in the menu's code if nothing has changed will help greatly, bailing in the post update handlers if nothing has changed would also help in general.

#3 @pento
8 years ago

I'm inclined to bail early in wp_update_nav_menu_item() - that way, we get to avoid all of the update_post_meta() calls, too.

Alternatively, it might be useful to check if each post meta item has changed before updating it - that way, even menu items that have changed update faster.

As wp_update_post() already retrieves the post before updating, we could probably do a similar sanity check there.

Note: See TracTickets for help on using tickets.