Skip to content
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

Performance improvements. #321

Merged
merged 2 commits into from May 14, 2024
Merged

Conversation

rupertj
Copy link
Member

@rupertj rupertj commented May 2, 2024

Stopped block constructor loading entities. Changed getCurrentAlertBanners method so it can be called multiple times without re-loading banners.

Fixes #320

…nners method so it can be called multiple times without re-loading banners.
@andybroomfield
Copy link
Contributor

Thanks @rupertj. I'll take a look and test, seems straight forward.
Do we actully need to store the results of getCurrentAlertBanners() at all. If its caching isn't that what entitiy type manager is meant to do.
I've been meaning to move the logic into a service, and maybe use Big pipe to render them, which might simplify things.

@rupertj
Copy link
Member Author

rupertj commented May 3, 2024

Thanks for looking @andybroomfield :) My understanding is that the entity storage doesn't cache results of entity queries. Even if it does, we might as well save the cache lookup and keep the results around, as we're guaranteed to need them again to build the cacheability metadata.

@andybroomfield
Copy link
Contributor

andybroomfield commented May 7, 2024

Thanks @rupertj. The changes make sense, removing the call to getCurrentBanners in the constructor, but I wonder if we can actully elimnate the double call for cache tags.
In BHCC, a lot of our custom blocks use the pattern

// Add cache tags and context to back link block.
$build['#cache']['tags'][] = 'origin_node_id:' . $origin_node_id;
$build['#cache']['contexts'][] = 'url';

and dont include a getCacheTags() and getCacheContexts methods. Could a simmilar thing work here?

.. Looking at it more deeply, I see theres a bit of complexity in the getCacheContexts method that I need to look at to see if thats the best solution. I'm also wondering why the cacheContexts don't bubble up from the alert banner entities themselves.

@rupertj
Copy link
Member Author

rupertj commented May 7, 2024

You make a good point. I'd probably do the cache metadata like this if I was starting from scratch: https://github.com/localgovdrupal/localgov_publications/blob/bf29b24b406324f4b9294f1a67756a3a5272201d/src/Plugin/Block/PublicationPageHeaderBlock.php#L88

(Why there's so many different ways to do it, I don't know...)

Copy link
Contributor

@andybroomfield andybroomfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've being trying to see if there is a way to refactor without success. So if this is working for others I'd be happy to merge now, and I'm going to look at refacoring the logic when we move this to a service.

@finnlewis finnlewis merged commit 0032959 into 1.x May 14, 2024
8 checks passed
@finnlewis finnlewis deleted the fix/1.x/320-banners-loaded-unnecessarily branch May 14, 2024 11:17
@andybroomfield andybroomfield mentioned this pull request May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alert banners are loaded unnecessarily.
3 participants