Make WordPress Core

Opened 2 months ago

Closed 2 months ago

Last modified 2 months ago

#62818 closed defect (bug) (fixed)

Walker_Nav_Menu duplicated queries introduced by get_privacy_policy_url() call

Reported by: arzola's profile arzola Owned by: westonruter's profile westonruter
Milestone: 6.8 Priority: normal
Severity: normal Version: 6.2
Component: Menus Keywords: has-patch commit
Focuses: performance Cc:

Description

The start_el() method in Walker_Nav_Menu currently calls get_privacy_policy_url() for every menu item when building menus. This results in redundant queries, particularly for menus with many items.

if ( get_privacy_policy_url() === $menu_item->url ) {
        $atts['rel'] = empty( $atts['rel'] ) ? 'privacy-policy' : $atts['rel'] . ' privacy-policy';
}

get_privacy_policy_url should be memoized and called outside of this scope because it will be triggered for each element when building menus, resulting in tons of duplicated queries

Attachments (1)

62818.patch (5.0 KB) - added by arzola 2 months ago.

Download all attachments as: .zip

Change History (18)

This ticket was mentioned in PR #8140 on WordPress/wordpress-develop by @arzola.


2 months ago
#1

  • Keywords has-patch added; needs-patch removed

The start_el() method in Walker_Nav_Menu currently calls get_privacy_policy_url() for every menu item when building menus. This results in redundant queries, particularly for menus with many items. This patch memoizes the get_privacy_policy_url() result, improving performance while maintaining existing functionality.

#2 @swissspidy
2 months ago

  • Keywords needs-testing added
  • Version changed from 6.7.1 to 6.2

@arzola commented on PR #8140:


2 months ago
#3

I just fixed the tests behaviour, they were running well in isolation but failing when running all

#4 @arzola
2 months ago

Ok false alarm I need to work the tests changes because they run well on isolation but when the entire tests suite is running they fail, not sure what I'm doing wrong

#5 @arzola
2 months ago

Updated PR and solution

@arzola commented on PR #8140:


2 months ago
#6

Thank you @westonruter I'm kinda lost what's the next step hahaha, should I open a SVN PR?, not sure what to do

@westonruter commented on PR #8140:


2 months ago
#7

Ah, the next step is for a committer to take your code and commit to SVN. So your work here is done!

#8 @westonruter
2 months ago

  • Milestone changed from Awaiting Review to 6.8

#9 @westonruter
2 months ago

  • Owner set to westonruter
  • Status changed from new to accepted

@arzola
2 months ago

#10 @westonruter
2 months ago

@arzola FYI: There's no harm in attaching the patch to a ticket, but in reality it's easier to just use the PR directly. So you can skip having to do that in the future. Thanks!

#11 @arzola
2 months ago

Gotcha, thank you very much for your guidance

#12 @mukesh27
2 months ago

  • Keywords needs-refresh added

#13 @arzola
2 months ago

Do I need to do something here? like rebasing my branch or something like that? :)

#14 @westonruter
2 months ago

@arzola No, just apply the suggestions that @mukesh27 made to your PR.

#15 @westonruter
2 months ago

  • Keywords commit added; needs-testing needs-refresh removed

#16 @westonruter
2 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 59674:

Menus: Improve performance by calling get_privacy_policy_url() once per Walker_Nav_Menu instance rather than for every nav menu item.

The start_el() method in Walker_Nav_Menu was calling get_privacy_policy_url() for every menu item when building menus. This resulted in redundant queries, particularly for menus with many items. This obtains the get_privacy_policy_url() value in the constructor for reuse in the start_el() method to improve performance.

Redundant code to construct the privacy policy page is also refactored into the set_up() method during tests.

Props arzola, swissspidy, westonruter, mukesh27.
Fixes #62818.

#17 @westonruter
2 months ago

@arzola Congrats on your first commit props! Thank you for your contribution, not only opening a ticket but also providing the patch to fix it.

Note: See TracTickets for help on using tickets.