Opened 3 years ago
Closed 7 months ago
#15400 closed enhancement (fixed)
Recent comments widget triggers query for each post not in cache
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.5 |
| Component: | Comments | Version: | |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | WordPress@…, mitcho@… |
Description
Ideally, we should reduce this to a single query.
Attachments (6)
Change History (26)
- Milestone changed from 3.1 to Future Release
- Type changed from defect (bug) to enhancement
- Keywords needs-patch added; 3.2-early removed
- Milestone changed from Future Release to 3.1
comment:4
voyagerfan5761 — 3 years ago
- Cc WordPress@… added
- Keywords 3.2-early added
- Milestone changed from 3.1 to Future Release
Punting due to beta.
I think in general this Widget makes too many queries as we also run queries for all the links to work out which page the comments are on when comment paging is enabled.
I've reviewed your patch and have the following comments.
- You shouldn't directly access/delete cache objects from within the widget code
- It would be better to do two queries one to fetch the comments and one with get_posts to fetch and cache the posts.
comment:10
nacin — 9 months ago
- Keywords needs-patch added; has-patch 3.2-early gci removed
- Milestone changed from Future Release to 3.5
We can now use _prime_post_caches() here.
- Cc mitcho@… added
- Keywords has-patch added; needs-patch removed
comment:12
nacin — 8 months ago
A term cache *might* be necessary if the permalink has term structures like %category%. I'm fine with the patch as is, but something to think about.
I propose that we open another ticket to create something like a permalinks_include_terms() function (which may have other uses elsewhere?), but otherwise land this for the time being. Nacin, thoughts?
comment:14
in reply to:
↑ 6
nacin — 8 months ago
Replying to westi:
I think in general this Widget makes too many queries as we also run queries for all the links to work out which page the comments are on when comment paging is enabled.
I forgot about this part.
comment:15
nacin — 8 months ago
- Component changed from Cache to Comments
comment:16
nacin — 8 months ago
Let's at least get _prime_post_caches() in for 3.4. I am thinking we do this as a play-it-safe:
_prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
comment:17
nacin — 8 months ago
And by 3.4, I mean 3.5. Tough to keep track these days.
comment:18
nacin — 8 months ago
- Keywords commit added
comment:19
nacin — 7 months ago
In [22278]:
comment:20
nacin — 7 months ago
- Resolution set to fixed
- Status changed from new to closed
Opened #22261 for pagination-related queries.

Sorry, I misread the 3.1 schedule. This can still go in until Nov. 15.