Add open and closed post counts to project#342
Merged
Conversation
A project should be able to return the number of open posts as well as the number of closed posts. This update adds two counter caches to the project model: `open_posts_count` and `closed_posts_count`. These new attributes reflect the count of posts matching the statuses of their namesake. The [`test_after_commit`](https://github.com/grosser/test_after_commit) gem is needed, as transactional fixtures are enabled and counter caches are updated in an `after_commit` callback. See [magnusvk/counter_culture#a-note-on-testing](https://github.com/magnusvk /counter_culture#a-note-on-testing) for more info. This will no longer be needed in Rails 5: [rails/rails/pull/18458](rails/rails#18458). To update existing counters, run the following: ```ruby Post.counter_culture_fix_counts https://github.com/magnusvk/counter_culture#manually-populating-counter- cache-values ``` Resolves #323 Ignore localhost Enable elasticsearch on circleci
0d9bbe2 to
e7488ea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A project should be able to return the number of open posts as well as the number of closed posts. This update adds two counter caches to the project model:
open_posts_count– The number of open posts for the project.closed_posts_count– The number of closed posts for the project.The
test_after_commitgem has also been added to thetestgroup, and is necessary because transactional fixtures are enabled and counter caches are updated in anafter_commitcallback. See magnusvk/counter_culture for more info. This will no longer be needed in Rails 5: rails/rails/pull/18458.To update existing counters, the following can be run:
Closes #323