Opened 7 years ago
Closed 6 years ago
#43514 closed defect (bug) (fixed)
`get_pages()` DB query result not cached if nothing found
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Query | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
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)
Change History (8)
Note: See
TracTickets for help on using
tickets.
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
).