Skip to content

Homepage content blocks cache#6235

Merged
ivan-mr merged 12 commits intodecidim:developfrom
armandfardeau:performance/homepage-content-blocks-cache
Oct 13, 2020
Merged

Homepage content blocks cache#6235
ivan-mr merged 12 commits intodecidim:developfrom
armandfardeau:performance/homepage-content-blocks-cache

Conversation

@armandfardeau
Copy link
Copy Markdown
Contributor

@armandfardeau armandfardeau commented Jun 23, 2020

🎩 What? Why?

Add cache to homepage content blocks
This P.R. is an implementation proposal for a caching and hash testing strategy.

📌 Related Issues

📋 Subtasks

  • Add tests

private

def perform_caching?
false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can define cache_hash in the ViewModel, make it return nil by default, and change perform_caching? body to cache_hash.present? so that you skip required method 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes thank you!

@andreslucena
Copy link
Copy Markdown
Member

Hi @armandfardeau can you please fix the title and link the github issue 🙏 ? Thanks

@armandfardeau armandfardeau changed the title Performance/homepage content blocks cache Homepage content blocks cache Jun 25, 2020
Copy link
Copy Markdown
Contributor

@tramuntanal tramuntanal left a comment

Choose a reason for hiding this comment

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

Hi @armandfardeau good start! 👏
I've just left you a couple of questions so that we are aligned when you retake this PR

private

def cache_hash
"decidim/content_blocks/hero/#{Digest::MD5.hexdigest(model.attributes.to_s)}/#{current_organization.cache_version}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why don't use model.updated_at instead of hashing all the attributes?
shouldn't we take into account also the current locale?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Definitely the locale is needed so we have a cached version for each one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

why don't use model.updated_at instead of hashing all the attributes?
shouldn't we take into account also the current locale?

The model doesn't have an updated_at attribute in this case, nor a cache_version therefore it is needed to hash all attributes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

definitely, I just added them

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why don't use model.updated_at instead of hashing all the attributes?

I thought exactly the same when reviewing this... @armandfardeau could you add your answer as a comment in the code 🙏 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

why don't use model.updated_at instead of hashing all the attributes?

I thought exactly the same when reviewing this... @armandfardeau could you add your answer as a comment in the code 🙏 ?

For sure.

private

def cache_hash
"decidim/content_blocks/last_activity/#{Digest::MD5.hexdigest(valid_activities.map(&:updated_at).to_s)}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same as with the preivous cell

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

same as with the preivous cell

In this case, suppose that the number of valid activities increases to a large number, which means a long identification key for the cache system to find. With an MD5 hash, we make sure that the key will remain the same length.

@armandfardeau
Copy link
Copy Markdown
Contributor Author

I will be able to work on it on Monday, thanks for your feedbacks

@stale
Copy link
Copy Markdown

stale bot commented Sep 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. @carolromero & @andreslucena feel free to chime in.

@stale stale bot added the wontfix label Sep 20, 2020
@stale stale bot removed the wontfix label Sep 21, 2020
@armandfardeau armandfardeau marked this pull request as ready for review September 21, 2020 18:23
@armandfardeau
Copy link
Copy Markdown
Contributor Author

armandfardeau commented Sep 21, 2020

@andreslucena It's been a long time and I should have moved on this but I think we need to open the door to a standardised way of testing hash of cached items. This implementation is a modest proposal.

@mrcasals
Copy link
Copy Markdown
Contributor

@armandfardeau I love French, but do you mind translating your previous comment into English? I'm guessing you had a rough day and it just slipped 🙈

@armandfardeau
Copy link
Copy Markdown
Contributor Author

armandfardeau commented Sep 22, 2020

@armandfardeau I love French, but do you mind translating your previous comment into English? I'm guessing you had a rough day and it just slipped see_no_evil

Damn what a messy day! thanks

ivan-mr
ivan-mr previously approved these changes Sep 23, 2020
Copy link
Copy Markdown
Contributor

@ivan-mr ivan-mr left a comment

Choose a reason for hiding this comment

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

Everything seems ok. Thanks @armandfardeau !

@ivan-mr
Copy link
Copy Markdown
Contributor

ivan-mr commented Sep 23, 2020

There's an internal error in the repository. As soon as we solve it I will merge this PR.
Thanks @armandfardeau !

@armandfardeau
Copy link
Copy Markdown
Contributor Author

There's an internal error in the repository. As soon as we solve it I will merge this PR.
Thanks @armandfardeau !

That Segfault looks like a nightmare, good luck

@ivan-mr
Copy link
Copy Markdown
Contributor

ivan-mr commented Sep 25, 2020

The segfault is now fixed in develop branch. Can you merge it with your branch to solve it @armandfardeau , please? Thanks!

@mrcasals
Copy link
Copy Markdown
Contributor

@armandfardeau there's something funky with the cache and the tests!

@armandfardeau
Copy link
Copy Markdown
Contributor Author

@armandfardeau there's something funky with the cache and the tests!

Thanks, I forgot to get back to English after switching locale, silly me.

However, there are some issues on Meetings and Admin (I suspect a drop in performance)

@armandfardeau
Copy link
Copy Markdown
Contributor Author

@ivan-mr Is the error I encounter a known flaky?

@ivan-mr
Copy link
Copy Markdown
Contributor

ivan-mr commented Oct 13, 2020

@ivan-mr Is the error I encounter a known flaky?

The meeting test failure seems to be a flaky but the error on Admin you say, I don't see any error on it.
Anyway, seems to be solved right now?

Copy link
Copy Markdown
Contributor

@ivan-mr ivan-mr left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks @armandfardeau !

@ivan-mr ivan-mr merged commit e29c9e3 into decidim:develop Oct 13, 2020
@armandfardeau armandfardeau deleted the performance/homepage-content-blocks-cache branch October 14, 2020 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Last activities home page block causes performance trouble

6 participants