Object caching is incompatible with mutative the_posts filters.
|Reported by:||Antiarc||Owned by:||ryan|
|Component:||Cache API||Keywords:||has-patch needs-testing 2nd-opinion early|
query.php runs something like:
- Get the posts
- Run the_posts filters
- Save $posts in object cache
The problem is that when you go to edit a post, get_post() checks the object cache for a post before pulling it from the DB. Thus, presume the following:
- We pull a post, with the content "foo".
- We run a the_posts hook, maybe with a regex that transforms "foo" into "foobar".
- $posts are saved in the object cache
- We go to edit a post. Post is pulled from the object cache, as "foobar" - not what the user entered into their post.
- We save the post without any editing. Post gets saved as "foobar".
- The post is pulled from the DB and the_posts is run. Our regex transforms it to "foobarbar", etc etc.
I know that transformative actions are generally done on the_content, but in this particular case, I absolutely have to be doing batched operations on all posts pulled (it's sending content off to a remote server for processing, and running that on the_content would generate N requests per page, rather than 1 request per page, incurring massive slowdown). The docs do not forbid transformation by the_posts, and I can't find a more appropriate hook to use, nor is there a hook to invalidate the contents of the object cache before editing happens.
This used to be correct, but was changed in r4517 - the commit message there is kind of bogus. I've attached a patch with the fix.
Change History (15)
- Keywords tested added
- Milestone changed from Unassigned to 2.8