Ipstenu / varnish-http-purge

Proxy Cache Purge
Apache License 2.0
46 stars 47 forks source link

All purges happen twice with Gutenberg Editor #86

Open ckeeney opened 4 years ago

ckeeney commented 4 years ago

When a post is saved using the Gutenberg editor, the editor makes two separate requests to save all the data: one request to save metaboxes and one request to save the post itself. Both of these requests dispatch a save_post event. As a result, all of the purges happen twice. This is causing performance issues: most notably, it worsens the slow saving of posts documented in #56.

There are a few workarounds in the comments at https://github.com/WordPress/gutenberg/issues/12903, but I'm not sure which is best.

Ipstenu commented 4 years ago

The issue, as mentioned in Gutenberg's ticket, is that Gutenberg itself is saving twice IF there's a meta box. There's no easy way to check if something is gutenberg and if it did (or didn't) already save the meta, so you kind of have to deal with a double purge until there's a better hook :(

Also most of the proposed fixes require knowing the post type you're hooking into (post, pages, custom...) which I can't know. Unlike the fix used for social media posts, we want to run on update as well as on initial post, but it's possible to take some of https://gist.github.com/n7studios/56fd05f19f5da26f19f6da0ccb57b144#file-post-to-social-php-L67 and use that to determine. I'll mess around with it.

FWIW since I'm not watching post transitions in the same way, it's not a 1-to-1 same situation :/

ckeeney commented 4 years ago

I agree the most ideal solution involves changes to WP Core hooks. I just noticed the duplicate purge requests and wanted to document the behavior here so people didn't spend time investigating something I already researched.