Opened 17 years ago
Closed 16 years ago
#10615 closed defect (bug) (fixed)
Recent Comments Widget Should Use Comments API
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 3.0 | Priority: | normal |
| Severity: | normal | Version: | 2.9 |
| Component: | Comments | Keywords: | has-patch dev-feedback needs-testing |
| Focuses: | Cc: |
Description
Currently it makes a direct database query.
Patch calls get_comments() instead.
Attachments (6)
Change History (27)
#2
@
17 years ago
- Cc westi added
Patch looks good.
I wonder if the old caching mech was trying to be clever for multiple widget instances so they all used the same cache hence always getting 15 comments
don't know if we want to preserve that behaviour.
It means that if you use the widget three times but with different comment counts its only one cache entry to store and invalidate.
#3
@
17 years ago
I think you're right about the intent. However, having multiple instances of the recent comments widget seems like too obscure a situation to justify the unnecessary queries.
I think that also explains why the max limit was set to 15. Without the caching cleverness, that limit is unnecessary, so I removed it from the second patch.
#4
follow-up:
↓ 5
@
17 years ago
Why remove the explicit caching? That will force blogs with persistent cache to run the rest of the code on almost every page load.
#5
in reply to:
↑ 4
;
follow-up:
↓ 7
@
17 years ago
Replying to azaozz:
Why remove the explicit caching? That will force blogs with persistent cache to run the rest of the code on almost every page load.
Ok, taking that into account, third patch does what the recent posts widget cache does: it uses the query API but caches the printed output.
Improvements:
- Still using API instead of direct db calls
- Likely to have to query less in most cases, as default 5 queried comments is less than previous 15 comments no matter what.
- Persistent cache of output instead of serialized comment objects means we're caching a smaller amount of data but interrupting sooner, thereby reducing processing and memory use.
#7
in reply to:
↑ 5
;
follow-up:
↓ 8
@
16 years ago
Replying to filosofo:
Replying to azaozz:
Why remove the explicit caching? That will force blogs with persistent cache to run the rest of the code on almost every page load.
Ok, taking that into account, third patch does what the recent posts widget cache does: it uses the query API but caches the printed output.
Improvements:
- Still using API instead of direct db calls
- Likely to have to query less in most cases, as default 5 queried comments is less than previous 15 comments no matter what.
- Persistent cache of output instead of serialized comment objects means we're caching a smaller amount of data but interrupting sooner, thereby reducing processing and memory use.
Looks good.
Do we really need to use output buffering and echos here?
Can we not just build up the html as a string and cache that?
#8
in reply to:
↑ 7
@
16 years ago
Replying to westi:
Do we really need to use output buffering and echos here?
No. I was desperately trying to get get_comments() in instead of querying the database directly, so to respond to the above criticism I just copied the recent posts widget almost exactly. (Recent posts, the calendar, and various chunks of the admin use the output buffering trick).
How about a patch that builds the HTML for recent comments as well as recent posts, so we're somewhat consistent?
#9
@
16 years ago
Regarding Cache and multiple widgets please see this ticket which should contain a fix for the problem: #11580
#10
@
16 years ago
- Keywords needs-patch added; get_comments WP_Widget_Recent_Comments has-patch removed
widget_comments_use_api.10615.persistent_cache.diff is erroneous. the last call to wp_cache_add() is bogus (it's missing an argument), and it should be using wp_cache_set() instead.
#11
@
16 years ago
Whoops. However, aside from the missing argument it's the same as the recent posts widget. I'll see how the dust settles on that and imitate it for recent comments.
#13
@
16 years ago
Just a thought -- custom comment types will show up in the widget, and plugins have no control over that currently unless they filter on the SQL itself. Using the API should allow for a plugin to filter that nicer.
#14
@
16 years ago
- Keywords has-patch dev-feedback needs-testing added; needs-patch removed
This is basically the same patch as filosofo submitted but its built off of the current revision and it doesn't use output buffering. Comments / suggestions?
@
16 years ago
This diff actually puts the $cache var into cache... removes limit label in GUI as well
Relates to #10612