pluginkollektiv / cachify

Smart but efficient cache solution for WordPress. Use DB, HDD, APC or Memcached for storing your blog pages. Make WordPress faster!
https://wordpress.org/plugins/cachify/
GNU General Public License v2.0
99 stars 31 forks source link

wp_delete_post_revision() flushes complete cache #245

Closed ouun closed 2 years ago

ouun commented 2 years ago

Describe the bug Thanks for the ongoing work on this simple and great plugin. I just realized that the automatic processing function wp_delete_post_revision() calls wp_delete_post() to delete the revisions. This flushes the complete Cachify cache as do_action('before_delete_post') is triggered.

This flushes the complete page cache unnecessarily as post revisions won't get cached at all. Deleting them has no impact on the frontend.

To Reproduce Steps to reproduce the behavior:

  1. Limit revisions in wp-config: define('WP_POST_REVISIONS', 1)
  2. Edit a post that has already revisions
  3. Note that wp_delete_post_revision() is executed
  4. Check your cache
  5. Realize it is gone

Expected behavior Cache flushes only for posts with status "publish". The hook before_delete_post can pass $post_id and $post to the flush_total_cache() function. A check for the post status could help, here. Please let me know if you are open for a PR into this direction.

System (please complete the following information):

Zodiac1978 commented 2 years ago

Please let me know if you are open for a PR into this direction.

Hi @ouun and thanks for your issue!

I haven't looked myself at the code, but your explanation and solution looks fine for me. Would be great if you submit a PR for further discussions.

ouun commented 2 years ago

Hi @Zodiac1978,

thanks for your answer. I just went ahead and dived a bit deeper into Cachify. Got a bit confused as I realized that the wp_trash_post hook will clear the complete cache, too. Nevertheless there is a method delete_item() for individual post cache flushing available for each Caching Method (DB, HDD,...) and cachify_remove_post_cache as a hook, that is never executed. However I started with a PR here and therefore close this one: https://github.com/pluginkollektiv/cachify/pull/247

Zodiac1978 commented 2 years ago

Let's keep this issue open until the PR is merged. For better tracking I have linked the issue and the PR.