WordPress.org

Make WordPress Core

Opened 18 months ago

Last modified 18 months ago

#36891 new enhancement

Saving large menus is super slow

Reported by: pento Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Menus Keywords:
Focuses: administration, performance Cc:

Description

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
18 months 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
18 months 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
18 months 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.