greenpeace / planet4

Built on top of Wordpress tech, Greenpeace Planet 4 powers digital platforms to engage with millions and win campaigns around the world.
https://planet4.greenpeace.org
Creative Commons Attribution Share Alike 4.0 International
64 stars 26 forks source link

When a GravityForm is updated, purge the page cache of pages that contain the form #184

Closed stduerre closed 1 year ago

stduerre commented 1 year ago

Feature summary:

At the moment, when a GravityForm is updated, the old version is still being served from caches. Editors have to manually go to the pages that contain the form and save them again, which triggers a cache delete. It's a manual process that editors often forget, resulting in us serving old content.

This feature would automatically purge all caches of the pages that contain the form whenever a form is updated. That includes local cache on the server (object cache) and CDN/Cloudflare caches.

Proposal & Constraints:

Here's a first proposal for a solution.

I also did some research into other solutions and clearing the cache directly. The Cloudflare plugin we use doesn't support clearing page cache programmatically. Cloudflare does have an API that could be used, but it's more complicated, needs more maintainance and we'd have to manage API keys to use it. Local caches would have to be treated separately. That's why simulating a page save is my preferred solution, it's much simpler and requires less maintainance.

In my tests, I could not find any side effects. I didn't notice a change to the post, not even a new revision.

Additional context:

A discussion about performance would be interesting. It would be much better if we could find the blocks (only those with the correct formId) directly through WP_Query instead of going through all posts that contain a gravityforms/form form block and filter for the formId. I couldn't get that to work yet, regular expression searching seems to be only possible on meta values of posts, not the content.

lithrel commented 1 year ago

Looking good :+1: two things to add:

stduerre commented 1 year ago

we could also take reusable blocks into account (so probably querying reusable blocks for those using GF, and then querying posts using those)

Good point! Totally makes sense to include reusable blocks.

we have a custom block search

Ah yes, that looks promising for better performance :slightly_smiling_face:

comzeradd commented 1 year ago

Thanks @stduerre for the detailed proposal. Feel free to open a PR directly in the master-theme when ready.

stduerre commented 1 year ago

PR is ready for review/discussion. It now also finds the form block when they are used within reusable blocks.