putyourlightson / craft-blitz

Intelligent static page caching for creating lightning-fast sites with Craft CMS.
https://putyourlightson.com/plugins/blitz
Other
147 stars 35 forks source link

Problem with refreshCacheWhenElementSavedUnchanged in Craft 5 entrification era #654

Closed gregorydavidjenkins closed 2 months ago

gregorydavidjenkins commented 2 months ago

Bug Report

I have a matrix field that can create an entry type which includes an asset field. There are a few meta fields on the asset elements themselves (caption, etc.). When I click on an asset within the matrix field to edit the asset, then make changes to the asset and save them, the page that contains the matrix field (and its child assets) doesn't get refreshed.

I searched and found this issue from a long time ago: https://github.com/putyourlightson/craft-blitz/issues/235

And thought it would solve my issue. But it didn't, and I think I know why, but I'm not totally sure.

When I edit the asset, the cache for the page doesn't get refreshed. And, interestingly when I edit the top-level entry (the title for example) it also doesn't refresh the cache. In other words, I don't see those asset-level meta changes on the FE after editing the asset or the parent entry.

However, I do see the changes on the front end when I change some other field inside of the matrix-created entry that contains the asset.

In other words, in my use case the thing that needs refreshed is the matrix-created entry, but it isn't ever getting saved with the "edit the asset" flow. And it isn't getting saved when I re-save the parent entry.

I don't think refreshCacheWhenElementSavedUnchanged is refreshing the caches of what we used to call matrix blocks, but are now just entries in and of themselves.

Plugin Version

5.0.0

Craft CMS Version

5.0.2

PHP Version

8.2.18

gregorydavidjenkins commented 2 months ago

As I re-read my post I think a visual would be helpful. Screenshot here...

blitz-matrix
bencroker commented 2 months ago

This should work. Can you verify that the asset element is being tracked by that page in Blitz Diagnostics → Pages? Also, do you have a queue runner set up? A refresh cache queue job should be started as soon as the asset it saved. If the queue is run via a web request then an extra request to the CP may be necessary to kick it off.

bencroker commented 2 months ago

Please also ensure you’re on the latest plugin version, currently 5.1.1.

gregorydavidjenkins commented 2 months ago

Updated to 5.1.1, confirmed that the asset is being tracked by that page in Blitz Diagnostics → Pages.

I don't see a refresh cache queue job in the queue when I save the asset (or the page or anything else). I see other jobs (update search index, generate site maps (SEOmatic).

gregorydavidjenkins commented 2 months ago

I think I don't see a job because we have a blitz specific queue runner, but nevertheless it's still not working as expected (with latest plugin version and confirmed diagnostics above).

bencroker commented 2 months ago

I figured out where in the code the issue was. Fixed in https://github.com/putyourlightson/craft-blitz/commit/ada9fdea24d314df8777c1d8bd5e3a439e16115e and released in 5.1.2. Thanks for the report!

gregorydavidjenkins commented 2 months ago

Thank you so much!