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

Use comments counter cache instead of additional query #7627

Merged
merged 2 commits into from Mar 25, 2021

Conversation

ahukkanen
Copy link
Contributor

@ahukkanen ahukkanen commented Mar 16, 2021

🎩 What? Why?

When browsing e.g. the blogs index, you can see from the benchmarks that there are bunch of COUNT queries done against the comments table.

The counter caches were already added at #6438 but they are not properly used.

It also does not work if we would add counter_cache: :comments_count to the commentable concern:

has_many :comments, as: :commentable, foreign_key: "decidim_root_commentable_id", foreign_type: "decidim_root_commentable_type", class_name: "Decidim::Comments::Comment"

Even after it is added there and the Comment model (as with other counter caches), the queries won't disappear.

The only way how I could figure out to get rid of the extra queries was by accessing the cache column directly.

📌 Related Issues

Testing

  • Create an instance with the test seeds
  • Go to one of the blogs components
  • Check the benchmark section at the top right
  • See a bunch of COUNT queries against the comments table (see screenshot)

📋 Checklist

  • CONSIDER adding a unit test if your PR resolves an issue.
  • ✔️ DO check open PR's to avoid duplicates.
  • ✔️ DO keep pull requests small so they can be easily reviewed.
  • ✔️ DO build locally before pushing.
  • ✔️ DO make sure tests pass.
  • ✔️ DO make sure any new changes are documented in docs/.
  • ✔️ DO add and modify seeds if necessary.
  • ✔️ DO add CHANGELOG upgrade notes if required.
  • ✔️ DO add to GraphQL API if there are new public fields.
  • ✔️ DO add link to MetaDecidim if it's a new feature.
  • AVOID breaking the continuous integration build.
  • AVOID making significant changes to the overall architecture.

📷 Screenshots

Count queries in the benchmark tool

@mrcasals mrcasals merged commit ae036ee into decidim:develop Mar 25, 2021
entantoencuanto added a commit that referenced this pull request Mar 26, 2021
* develop: (64 commits)
  Fix report mailers when author is a meeting (#7683)
  New Crowdin updates (#7729)
  Fix form builder assuming proposals module availability (#7689)
  Fix a series of issues with proposal attachments in the public area (#7699)
  New Crowdin updates (#7711)
  Add accessibility labels to the <nav> menus (#7709)
  Fix heading order on the home page (#7710)
  Fix dropdown menu accessibility audits (#7708)
  Fix the aria attribute names (no aria prefix) (#7707)
  Fix validations for registration related fields in Conference form (#7675)
  New Crowdin updates (#7613)
  Use comments counter cache instead of additional query (#7627)
  Upgrade to decidim-bulletin_board 0.15.2 (#7659)
  Bump mimemagic to 0.3.6 (#7701)
  Ensure pagination elements per page is a valid option (#7680)
  Fix link to "Getting started guide" in README.adoc (#7695)
  Fix link to CONTRIBUTING.adoc in PR template (#7696)
  Fix the screen reader class name for comments opinion toggle (#7698)
  Fix initiative-m card hashtags (#7679)
  Don't run all jobs on every PR (#7693)
  ...
@ahukkanen ahukkanen deleted the fix/commentable-counter-cache-usage branch June 30, 2021 10:45
ahukkanen added a commit to mainio/decidim that referenced this pull request Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants