Make WordPress Core

Opened 3 years ago

Closed 5 weeks ago

#55958 closed enhancement (fixed)

Checking if _admin_notice_post_locked should be called can slow down the post editing

Reported by: berislavgrgicak's profile berislav.grgicak Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.8 Priority: normal
Severity: normal Version: 4.9
Component: Editor Keywords: has-patch
Focuses: performance Cc:

Description

On wp-admin/edit-form-advanced.php:28, WordPress checks if multiple users exist to call _admin_notice_post_locked.

In some cases, plugins add additional filters to all get_users calls to ensure that a user role doesn't have access to private data.
If these checks use meta value comparisons, it can slow post-editing on sites with large user_meta tables.

The root cause of this issue is how WordPress stores and validates user capabilities, but the _admin_notice_post_locked check could be optimized without fixing the root cause.

Some suggestions on how to fix this would be:

  • caching the $check_users value
  • using a boolean option that is true if a site has multiple users
  • adding a filter that allows manually setting $check_users to skip this check

Attachments (1)

55958.patch (2.0 KB) - added by bor0 5 weeks ago.

Download all attachments as: .zip

Change History (10)

#1 follow-up: @costdev
3 years ago

  • Focuses performance added
  • Type changed from defect (bug) to enhancement
  • Version changed from trunk to 4.9

Hi @berislavgrgicak, welcome to Trac!

I'm just modifying the ticket's parameters to help get this some more focus and help to track down when this was introduced.


This check was introduced in WordPress 4.9.

#2 in reply to: ↑ 1 @berislav.grgicak
3 years ago

Thank you @costdev!

I would be happy to help with this, but I'm not sure what would be the best way to improve the performance.

@bor0
5 weeks ago

#3 follow-up: @bor0
5 weeks ago

@costdev we just ran into this again recently.

We're hosting WooCommerce.com, a huge WooCommerce store, and we are receiving about 1000 "MySQL server has gone away" errors per month because of this issue.

I submitted a patch that fixes it for us, but it'd be great if it makes it into core to potentially fix it for other users.

#4 @bor0
5 weeks ago

  • Keywords has-patch added

cc @sergeybiryukov as well :)

#5 @SergeyBiryukov
5 weeks ago

  • Milestone changed from Awaiting Review to 6.8
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#6 @SergeyBiryukov
5 weeks ago

In 59522:

Editor: Check get_user_count() instead of get_users() for the locked post notice.

This aims to avoid slowing down the post editing by using a cached value instead of calling get_users(), which can be slow when plugins add various filters to all get_users() calls, especially with meta value comparisons on large user_meta tables.

Follow-up to [24304], [24543], [41829], [53011], [53018].

Props berislav.grgicak, bor0, costdev.
See #55958.

#7 in reply to: ↑ 3 @SergeyBiryukov
5 weeks ago

Replying to bor0:

I submitted a patch that fixes it for us, but it'd be great if it makes it into core to potentially fix it for other users.

Thanks for the ping! I think we can check get_user_count() here, see [59522]. Would that resolve the issue for you?

#8 follow-up: @bor0
5 weeks ago

Wow, thanks a ton, this will fix it for us!

I totally missed get_user_count() - so elegant. And it also doesn't rely on get_users, which is neat. I knew pinging you was the right thing to do :)

Tested on both multisite and non-multisite instances.

#9 in reply to: ↑ 8 @SergeyBiryukov
5 weeks ago

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

Replying to bor0:

Wow, thanks a ton, this will fix it for us!

Great, thanks for the confirmation :)

Note: See TracTickets for help on using tickets.