New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Related items going from disabled to live status does not clear cache of its relations. #555
Comments
That is indeed unexpected behaviour. Can you please show me the code you are using to output the related blog posts on the homepage? |
index.twig
_event_card.twig
|
Probably a very hard-handed solution, but right now I refresh cache on all entry saves as a solution. Basically most of the content edits will somehow affect the home page anyway in this particular site. Using a "clear the cache, regenerate manually or organically". Flushes the cache more often than I'd like, but atleast it solves the issue at hand. The client was sitting and waiting for the changes to show up on the home page 😅
|
I think I’ve gotten to the bottom of this and will work on a fix in the coming days. In the meantime, refreshing only the homepage might be a better approach. use craft\base\Element;
use craft\elements\Entry;
use craft\events\ModelEvent;
use putyourlightson\blitz\Blitz;
use putyourlightson\blitz\models\SiteUriModel;
use yii\base\Event;
Event::on(Entry::class, Element::EVENT_AFTER_SAVE, function(ModelEvent $event) {
/** @var Entry $entry */
$entry = $event->sender;
if ($entry->slug === 'homepage') {
Blitz::$plugin->refreshCache->refreshSiteUris([
new SiteUriModel([
'uri' => $entry->uri,
'siteId' => $entry->siteId,
]),
]);
}
}); |
It turns out this is a limitation rather than a bug. Because relation field queries can be eager-loaded but don’t necessarily have to be, tracking them is unreliable and is intentionally excluded. craft-blitz/src/services/GenerateCacheService.php Lines 250 to 253 in aa720f5
I’m exploring how to get around this by tracking elements with any status (enabled and disabled) so that the desired behaviour can be achieved, and I expect to have an update later this week. |
Fair enough. I guess it's kind of an edge case, and could be solved by changing their workflow. But it feels better to be able to adjust to their workflow than otherwise. Since they basically first add the inactive entry to the homepage, and then later activate it, it doesn't work with your suggestion to only update the homepage when that is saved (because it isn't saved again), but I used your suggestion to only also update the homepage on entry saves. That at least avoids refreshing the whole shabam every time :-) use craft\base\Element;
use craft\elements\Entry;
use craft\events\ModelEvent;
use putyourlightson\blitz\Blitz;
use putyourlightson\blitz\models\SiteUriModel;
use yii\base\Event;
Event::on(Entry::class, Element::EVENT_AFTER_SAVE, function(ModelEvent $event) {
/** @var Entry $entry */
$entry = $event->sender;
Blitz::$plugin->refreshCache->refreshSiteUris([
new SiteUriModel([
'uri' => '/',
'siteId' => 1,
]),
]);
}); |
Yup, that’ll do it! |
I managed to fix this in 3296e91 for the next release. If you can help by testing then that would be much appreciated! You can test this by running |
@bencroker I can confirm that this works in our use case. 🙌 |
Glad to hear it! |
Released in 4.6.0. |
Steps to reproduce the issue.
(assuming blitz installed and activated)
We have Page 1 (home page) and Page 2 (Blog post)
This is unexpected behaviour. The same does not happen the other way around.
ie. If a related blog post is listed on the home page, but gets deactivated it will clear the cache of the home page.
So the expected behaviour would be that activating a previously deactivated blog post should clear the cache of the home page.
The plugin and Craft version numbers.
Blitz 4.5.2
Craft Pro 4.4.17
PHP 8.2.8
The text was updated successfully, but these errors were encountered: