Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#48014 closed defect (bug) (fixed)

Multiple _encloseme entries in postmeta table when disabling pings

Reported by: rebasaurus's profile rebasaurus Owned by: whyisjake's profile whyisjake
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: Pings/Trackbacks Keywords: has-patch commit
Focuses: performance Cc:

Description

When we disable pings, this can lead to potentially hundreds of thousands rows accumulating with the _encloseme key on the postmeta table (as it is fired on every publish_post hook: https://github.com/WordPress/WordPress/blob/71cf332e6569f0ac2f263ce9b2168644942f5534/wp-includes/post.php#L6580) and therefore, cause performance issues on simple meta queries that are normally run on pageload:

SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (x) ORDER BY meta_id ASC

This is because the cleanup function do_all_pings() does not run anymore on the do_pings hook: https://github.com/WordPress/WordPress/blob/1e925a5ae3faccad31c48c810af3954d01a60f0e/wp-includes/comment.php#L2626

Attachments (2)

48014.diff (569 bytes) - added by rebasaurus 5 years ago.
We can utilize the 4th parameter of add_post_meta() to prevent duplicate entries.
48014.2.diff (1.3 KB) - added by whyisjake 5 years ago.

Download all attachments as: .zip

Change History (19)

@rebasaurus
5 years ago

We can utilize the 4th parameter of add_post_meta() to prevent duplicate entries.

#1 @whyisjake
5 years ago

  • Milestone changed from Awaiting Review to 5.3
  • Owner set to whyisjake
  • Status changed from new to accepted

#2 @whyisjake
5 years ago

  • Keywords has-patch added
  • Version changed from 5.2.3 to trunk

#3 @whyisjake
5 years ago

  • Keywords needs-unit-tests added

#4 @whyisjake
5 years ago

@rebasaurus,

Thanks for contributing this issue, and the associated patch. To get this included in 5.3, we should look at adding some unit tests, and maybe a cleanup routine during the upgrade.

#5 @whyisjake
5 years ago

Chatting with @jorbin, cleanup could be part of the upgrade routine or maybe a standalone plugin.

#6 @whyisjake
5 years ago

  • Type changed from enhancement to defect (bug)

#7 @whyisjake
5 years ago

This probably should have been update_post_meta() in the beginning...

This ticket was mentioned in Slack in #core by whyisjake. View the logs.


5 years ago

@whyisjake
5 years ago

#9 @whyisjake
5 years ago

The test I added isn't passing, just wanted to share as a starting for deeper testing, or another pass on the primary function. FWIW, changing to update_post_meta() is showing the same issue.

#10 @whyisjake
5 years ago

  • Keywords commit added

Ran this with @desrosj yesterday, tests are passing for him. I would love to get this committed and in beta 3.

This ticket was mentioned in Slack in #core by whyisjake. View the logs.


5 years ago

#12 @whyisjake
5 years ago

  • Keywords needs-unit-tests removed

#13 @johnbillion
5 years ago

  • Keywords commit removed

The test isn't passing for me, so either the test is faulty or the patch is. I'm still seeing multiple _encloseme meta entries for the test post created in test_publish_post_hook().

Investigating.

#14 @johnbillion
5 years ago

  • Keywords commit added

False alarm! Looks good.

#15 @johnbillion
5 years ago

  • Version trunk deleted

#16 @johnbillion
5 years ago

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

In 46426:

Pings/Trackbacks: Avoid adding multiple _pingme and _encloseme meta entries to a post when it gets updated prior to pings being done.

Props rebasaurus, whyisjake

Fixes #48014

#17 @johnbillion
5 years ago

In 46428:

Pings/Trackbacks: Remove a failing test that won't pass as long as WP_IMPORTING gets set during tests.

The _publish_post_hook() function checks for WP_IMPORTING before setting meta fields fir enclosures and pings, which means this test is doomed to fail.

The test can be re-implemented if the WP_IMPORTING constant gets moved to a function similar to how wp_installing() works for the WP_INSTALLING constant.

See #48014

Note: See TracTickets for help on using tickets.