#37184 closed defect (bug) (fixed)
Stop FOUND_ROWS running in comment query is cached
Reported by: | spacedmonkey | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.6 | Priority: | high |
Severity: | normal | Version: | 4.4 |
Component: | Comments | Keywords: | has-patch needs-unit-tests |
Focuses: | Cc: |
Description
In #36906 the comment group was made to be a persistent object cache group. This means that comment queries using wp_comment_query are now cached. However, if query is cached and the no_found_rows param is set to true, the SELECT FOUND_ROWS() query still runs. This query will return the incorrect value as the comment query with SQL_CALC_FOUND_ROWS will not have run. Likely the found rows will fall back to the main query on the page, giving the incorrect value of found comments. Found comments will be used for pagination of multi page comments, and it will only show the first page of comments.
Attachments (1)
Change History (10)
#4
@
8 years ago
- Keywords needs-unit-tests added
- Milestone changed from Awaiting Review to 4.6
- Owner set to boonebgorges
- Status changed from new to reviewing
Introduced in [34544] but more obvious with persistent comment caching. This should be fixed for 4.6.
I don't think there's any need to cache 'max_num_pages' since it can be calculated from found_comments.
#5
@
8 years ago
We save max pages as it is only generated when no_found_rows is set to false. Please see this comment [37868] where we have done the same in WP_Site_Query.
#7
@
8 years ago
- Status changed from reviewing to accepted
We save max pages as it is only generated when no_found_rows is set to false. Please see this comment [37868] where we have done the same in WP_Site_Query.
The cache should hold as little information as possible, to avoid cache bloat and potential bugs related to improper invalidation. Values that can be computed arithmetically from known values should not be cached for these reasons. IMO [37868] sets a bad precedent in this regard.
This style of caching / bug fix was applied to wp_site_query here [37868].