Opened 12 years ago
Closed 11 years ago
#21879 closed defect (bug) (fixed)
wp_count_posts() cache is not destroyed after post inserts and deletions
Reported by: | mark8barnes | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.4.2 |
Component: | Cache API | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
wp_count_posts()
caches its results, but that cache is not destroyed when posts are inserted, deleted, or transitioned. This can lead to incorrect counts.
The attached patch fixes that (although it doesn't destroy the cache set when $perm='readable'
in wp_count_posts()
, which would be more complex as we wouldn't know the name of the key(s), though it could be done with preg_match
).
Attachments (3)
Change History (8)
#2
in reply to:
↑ 1
@
12 years ago
Replying to nacin:
We don't bother with clearing the caches here because the counts group is a non-persistent group. I wouldn't be surprised if we don't clean caches for anything using the counts group.
I understand that, but you'll sometimes want to perform a bulk operation and check post counts during the operation (in my case, I was trying to prevent the last of a custom post type from being deleted). In that scenario wp_count_posts() returns incorrect data.
(Another option would be to add a parameter to wp_count_posts() to optionally ignore the cache.)
#3
@
11 years ago
- Keywords needs-testing removed
- Milestone changed from Awaiting Review to 3.9
This only needs to happen on 'transition_post_status'
. 21879.diff does this in_transition_post_status()
.
#4
@
11 years ago
- Keywords commit added
After writing some unit tests, turns out this way scarier than I thought. 21879.2.diff is the required fix. Gonna let this sit here for a little bit for feedback.
We don't bother with clearing the caches here because the counts group is a non-persistent group. I wouldn't be surprised if we don't clean caches for anything using the counts group.