Make WordPress Core

Opened 20 months ago

Closed 19 months ago

Last modified 19 months ago

#56386 closed enhancement (fixed)

Remove `@access private` from cache priming functions.

Reported by: peterwilsoncc's profile peterwilsoncc Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 6.1 Priority: normal
Severity: normal Version:
Component: Cache API Keywords: good-first-bug has-patch needs-dev-note
Focuses: performance Cc:

Description

WordPress includes and makes heavy use of several functions for priming object caches. These functions reduce the number of database calls by querying the database for these objects in bulk.

With the benefit of hindsight, I can't see why these functions are marked private. Furthermore, I think plugins should be actively encouraged to use them..

I suggest the @access private delegation be removed from the following functions:

  • _prime_post_caches()
  • _prime_term_caches()
  • _prime_comment_caches()
  • _prime_network_caches()
  • _prime_site_caches()
  • _get_non_cached_ids()

Change History (11)

#1 @desrosj
19 months ago

I can't find it in the handbook at the moment, but I believe the idea with the preceding _ underscore was for developers to easily know when a function should be considered private.

If we're removing @access private from these, would it make sense to deprecate the current functions in favor of prime_post_caches(), prime_term_caches(), etc.?

#2 @peterwilsoncc
19 months ago

A precedent I found in [46602] for #48251 retained the underscore prefix while removing the private delegation.

In the previous ticket, the functions in question appeared 13249 times in the plugin repo. In this case the functions in question appear 237 times in the plugin plugin repo. The most frequently used being post priming in some 5M+ installed plugins.

I can be convinced either way but worry deprecating the functions would create a lot of noise in logs to avoid a precedent that has already been set.

Last edited 19 months ago by peterwilsoncc (previous) (diff)

#3 @SergeyBiryukov
19 months ago

Good point, if we didn't drop the underscore from _doing_it_wrong(), _deprecated_function(), seems OK to keep it here too.

I suppose we could also introduce non-underscored aliases like prime_post_caches() or wp_prime_post_caches(), but I'm not sure if there's a strong reason for that at this time, so keeping the current names would be my preference.

Version 0, edited 19 months ago by SergeyBiryukov (next)

This ticket was mentioned in PR #3134 on WordPress/wordpress-develop by robinwpdeveloper.


19 months ago
#4

  • Keywords has-patch added; needs-patch removed

Removed @access private from below functions (as per ticket description):

  • _prime_post_caches()
  • _prime_term_caches()
  • _prime_comment_caches()
  • _prime_network_caches()
  • _prime_site_caches()
  • _get_non_cached_ids()

Trac ticket: 56386

robinwpdeveloper commented on PR #3134:


19 months ago
#5

@costdev Changes are pushed as per suggestion

#6 @mukesh27
19 months ago

  • Milestone changed from Awaiting Review to 6.1
  • Owner set to peterwilsoncc
  • Status changed from new to assigned

The PR got enough approval.

Assign to Peter for final review.

#7 @desrosj
19 months ago

Agreed that there's no strong reason for deprecating, and that it would potentially cause a lot of noise needlessly. If this was something that was done more often and we documented this practice more openly, I'd feel a bit stronger towards renaming/deprecating for consistency.

Keeping the names as is sounds good 👍🏼

#8 @peterwilsoncc
19 months ago

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

In 53944:

Cache API, Docs: Remove private delegation from cache priming functions.

Remove the private delegation from the following cache priming functions for various object types:

  • _prime_post_caches()
  • _prime_term_caches()
  • _prime_comment_caches()
  • _prime_network_caches()
  • _prime_site_caches()
  • _get_non_cached_ids()

Plugins and themes are now encouraged to use these functions to improve the performance of their code by reducing the number of database queries.

Props robinwpdeveloper, desrosj, SergeyBiryukov, mukesh27, costdev.
Fixes #56386.

peterwilsoncc commented on PR #3134:


19 months ago
#9

Merged in https://core.trac.wordpress.org/changeset/53944 / 541b4eb6462c8f48e235590a9be79ebc4954f66e

#10 @desrosj
19 months ago

  • Keywords needs-dev-note added

#11 @desrosj
19 months ago

This should be mentioned in the miscellaneous dev note.

Note: See TracTickets for help on using tickets.