Skip to content

Improve performance on comment rendering#12582

Merged
andreslucena merged 4 commits intodevelopfrom
chore/improve-cache-on-comments
Mar 14, 2024
Merged

Improve performance on comment rendering#12582
andreslucena merged 4 commits intodevelopfrom
chore/improve-cache-on-comments

Conversation

@alecslupu
Copy link
Copy Markdown
Contributor

🎩 What? Why?

This PR adds implementation from the comment I have posted here: #12555 (comment)

📌 Related Issues

Link your PR to an issue

Testing

Describe the best way to test or validate your PR.

📷 Screenshots

Please add screenshots of the changes you are proposing
Description

♥️ Thank you!

@alecslupu alecslupu added the type: fix PRs that implement a fix for a bug label Mar 11, 2024
@alecslupu
Copy link
Copy Markdown
Contributor Author

The spell check error has been fixed on #12581.

@alecslupu alecslupu marked this pull request as ready for review March 12, 2024 12:38
@andreslucena andreslucena changed the title Improve performance on comment rendering. Improve performance on comment rendering Mar 12, 2024
@andreslucena
Copy link
Copy Markdown
Member

@alecslupu do you have any way of validating this one? I'm trying to see it through the bullet queries. I don't see much difference in the number of queries.

Not only that, but I'm also trying with https://github.com/brunofacca/active-record-query-trace. I don't see much difference between this PR and develop.

Do you have any script or screenshot to check out the performance improvement?

@alecslupu
Copy link
Copy Markdown
Contributor Author

alecslupu commented Mar 12, 2024

Do you have any script or screenshot to check out the performance improvement?

@andreslucena
I have managed to use factory_bot for it. If you apply the below snippet, you should be able to view some improvements. There is a N+1 query caused by up_votes.any? { |vote| vote.author == user }.

When trying to render the comments list using the develop branch you should see a lot of SELECT * FROM decidim_users ... , whereas when applying this branch, you should not see those queries.

require "faker"
require "factory_bot"
require "decidim/core/test/factories"
require "decidim/participatory_processes/test/factories"
require "decidim/comments/test/factories"

Decidim::Comments::Comment.all.each do |comment|
  FactoryBot.create_list(:comment_vote, 50, :up_vote, comment: comment)
  FactoryBot.create_list(:comment_vote, 50, :down_vote, comment: comment)
end 

@andreslucena andreslucena self-assigned this Mar 13, 2024
Copy link
Copy Markdown
Member

@andreslucena andreslucena left a comment

Choose a reason for hiding this comment

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

Tried the provided script with the fixes, everything was really fast.

Tried the provided script with develop and I'm still waiting for it to finish 😅

Code-wise is 💯

@andreslucena andreslucena merged commit 1b6396e into develop Mar 14, 2024
@andreslucena andreslucena deleted the chore/improve-cache-on-comments branch March 14, 2024 12:09
andreslucena pushed a commit that referenced this pull request May 9, 2024
* use exists? instead of full collection traversal

* Add counter cache on cells

* replace query with counter cached version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: comments type: fix PRs that implement a fix for a bug

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants