Make WordPress Core

Opened 4 months ago

Last modified 2 months ago

#43514 new defect (bug)

`get_pages()` DB query result not cached if nothing found

Reported by: flixos90 Owned by:
Milestone: 5.0 Priority: normal
Severity: normal Version:
Component: Query Keywords: has-patch has-unit-tests
Focuses: Cc:


get_pages() uses a cache key in order to not have to query the DB when it's not necessary. However, if the DB query returns an empty result, that result is not cached, causing that DB query to be executed every time the function is called with these parameters.

Since the function uses wp_cache_get_last_changed( 'posts' ) anyway, it should be safe to also set an empty array if nothing is found, to prevent those unnecessary database requests.

Attachments (2)

43514.diff (870 bytes) - added by flixos90 4 months ago.
43514.tests.diff (939 bytes) - added by soulseekah 4 months ago.

Download all attachments as: .zip

Change History (5)

4 months ago

#1 @flixos90
4 months ago

  • Keywords has-patch added; needs-patch removed

43514.diff ensures that the cache key is also set when the DB query returns no results. The initial check after retrieving the cached value has been adjusted accordingly to be more strict, like it is commonly handled in core (check if value is not false).

4 months ago


#2 @soulseekah
4 months ago

  • Keywords has-unit-tests added; needs-unit-tests removed

Tests attached.

#3 @SergeyBiryukov
2 months ago

  • Milestone changed from Awaiting Review to 5.0
Note: See TracTickets for help on using tickets.