* modified index to allow retreival of comments belonging to either articles or podcast episodes
* updated comments section in api documentation to include info on podcast comments
* Remove DEV badge link (#9675)
* [deploy] Profile Admin UI Setup Screen Refactor (v1.5) (#9649)
* implement some suggestions from https://github.com/forem/forem/pull/9610
* chore: update the errors based on suggestions
* feat: make query readable on blazer
* added new parameter p_id to safe parameters
* Remove forward slash from br tags in pages partial (#9678)
* [deploy] Change lingering `/internal` paths to `/admin` (#9673)
* Change lingering `/internal` paths to `/admin`
* Fix multiline test expectation
* [deploy] Add new support admin role (#9681)
* Add new support admin role
* Allow support admins to banish users
* Fix spec order for new support admin role
* Migrate serialization to jsonapi-serializer (#9682)
This replaces the abandoned fast_jsonapi.
* [deploy] Async Handle Notifications for Comments When Saved (#9680)
* [deploy] Optimization: Change Large Table Primary Keys to Bigints (#9476)
* [deploy] Revert "Async Handle Notifications for Comments When Saved (#9680)" (#9686)
This reverts commit 852223dd86.
* Bump ddtrace from 0.38.0 to 0.39.0 (#9695)
* Bump ddtrace from 0.38.0 to 0.39.0
Bumps [ddtrace](https://github.com/DataDog/dd-trace-rb) from 0.38.0 to 0.39.0.
- [Release notes](https://github.com/DataDog/dd-trace-rb/releases)
- [Changelog](https://github.com/DataDog/dd-trace-rb/blob/master/CHANGELOG.md)
- [Commits](https://github.com/DataDog/dd-trace-rb/compare/v0.38.0...v0.39.0)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
* Bump ddtrace from 0.38.0 to 0.39.0 (Update vendor/cache)
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Bump vault from 0.14.0 to 0.15.0 (#9697)
* Bump vault from 0.14.0 to 0.15.0
Bumps [vault](https://github.com/hashicorp/vault-ruby) from 0.14.0 to 0.15.0.
- [Release notes](https://github.com/hashicorp/vault-ruby/releases)
- [Changelog](https://github.com/hashicorp/vault-ruby/blob/master/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/vault-ruby/compare/v0.14.0...v0.15.0)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
* Bump vault from 0.14.0 to 0.15.0 (Update vendor/cache)
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* [deploy] Optimization:Set Honeybadger send_data_at_exit to False (#9687)
* Travis Optimization:Bundle from Bash File to Use Cache (#9705)
* Bump stripe from 5.22.0 to 5.23.1 (#9692)
* Bump stripe from 5.22.0 to 5.23.1
Bumps [stripe](https://github.com/stripe/stripe-ruby) from 5.22.0 to 5.23.1.
- [Release notes](https://github.com/stripe/stripe-ruby/releases)
- [Changelog](https://github.com/stripe/stripe-ruby/blob/master/CHANGELOG.md)
- [Commits](https://github.com/stripe/stripe-ruby/compare/v5.22.0...v5.23.1)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
* Bump stripe from 5.22.0 to 5.23.1 (Update vendor/cache)
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* [deploy] Bump ancestry from 3.0.7 to 3.1.0 (#9689)
* Bump ancestry from 3.0.7 to 3.1.0
Bumps [ancestry](https://github.com/stefankroes/ancestry) from 3.0.7 to 3.1.0.
- [Release notes](https://github.com/stefankroes/ancestry/releases)
- [Changelog](https://github.com/stefankroes/ancestry/blob/master/CHANGELOG.md)
- [Commits](https://github.com/stefankroes/ancestry/compare/v3.0.7...v3.1.0)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
* Bump ancestry from 3.0.7 to 3.1.0 (Update vendor/cache)
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Bump rubocop from 0.88.0 to 0.89.0 (#9699)
* Bump rubocop from 0.88.0 to 0.89.0
Bumps [rubocop](https://github.com/rubocop-hq/rubocop) from 0.88.0 to 0.89.0.
- [Release notes](https://github.com/rubocop-hq/rubocop/releases)
- [Changelog](https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop-hq/rubocop/compare/v0.88.0...v0.89.0)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
* Bump rubocop from 0.88.0 to 0.89.0 (Update vendor/cache)
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Bump twilio-ruby from 5.39.2 to 5.39.3 (#9690)
* Bump twilio-ruby from 5.39.2 to 5.39.3
Bumps [twilio-ruby](https://github.com/twilio/twilio-ruby) from 5.39.2 to 5.39.3.
- [Release notes](https://github.com/twilio/twilio-ruby/releases)
- [Changelog](https://github.com/twilio/twilio-ruby/blob/main/CHANGES.md)
- [Commits](https://github.com/twilio/twilio-ruby/compare/5.39.2...5.39.3)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
* Bump twilio-ruby from 5.39.2 to 5.39.3 (Update vendor/cache)
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Bump ibm-openapi-validator from 0.28.0 to 0.28.1 (#9703)
Bumps [ibm-openapi-validator](https://github.com/IBM/openapi-validator) from 0.28.0 to 0.28.1.
- [Release notes](https://github.com/IBM/openapi-validator/releases)
- [Changelog](https://github.com/IBM/openapi-validator/blob/master/CHANGELOG.md)
- [Commits](https://github.com/IBM/openapi-validator/compare/v0.28.0...v0.28.1)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Bump sass-loader from 9.0.2 to 9.0.3 (#9702)
Bumps [sass-loader](https://github.com/webpack-contrib/sass-loader) from 9.0.2 to 9.0.3.
- [Release notes](https://github.com/webpack-contrib/sass-loader/releases)
- [Changelog](https://github.com/webpack-contrib/sass-loader/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack-contrib/sass-loader/compare/v9.0.2...v9.0.3)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Bump jsdom from 16.3.0 to 16.4.0 (#9701)
Bumps [jsdom](https://github.com/jsdom/jsdom) from 16.3.0 to 16.4.0.
- [Release notes](https://github.com/jsdom/jsdom/releases)
- [Changelog](https://github.com/jsdom/jsdom/blob/master/Changelog.md)
- [Commits](https://github.com/jsdom/jsdom/compare/16.3.0...16.4.0)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Bump eslint-plugin-react from 7.20.3 to 7.20.5 (#9694)
Bumps [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) from 7.20.3 to 7.20.5.
- [Release notes](https://github.com/yannickcr/eslint-plugin-react/releases)
- [Changelog](https://github.com/yannickcr/eslint-plugin-react/blob/master/CHANGELOG.md)
- [Commits](https://github.com/yannickcr/eslint-plugin-react/compare/v7.20.3...v7.20.5)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Flaky Spec Fix:HTML Escape Special Characters in Assertion like Template (#9708)
* Bump redoc-cli from 0.9.9 to 0.9.10 (#9698)
Bumps [redoc-cli](https://github.com/Redocly/redoc) from 0.9.9 to 0.9.10.
- [Release notes](https://github.com/Redocly/redoc/releases)
- [Changelog](https://github.com/Redocly/redoc/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Redocly/redoc/commits)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Bump css-loader from 4.2.0 to 4.2.1 (#9700)
Bumps [css-loader](https://github.com/webpack-contrib/css-loader) from 4.2.0 to 4.2.1.
- [Release notes](https://github.com/webpack-contrib/css-loader/releases)
- [Changelog](https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack-contrib/css-loader/compare/v4.2.0...v4.2.1)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Bump brakeman from 4.8.2 to 4.9.0 (#9691)
* Bump brakeman from 4.8.2 to 4.9.0
Bumps [brakeman](https://github.com/presidentbeef/brakeman) from 4.8.2 to 4.9.0.
- [Release notes](https://github.com/presidentbeef/brakeman/releases)
- [Changelog](https://github.com/presidentbeef/brakeman/blob/main/CHANGES.md)
- [Commits](https://github.com/presidentbeef/brakeman/compare/v4.8.2...v4.9.0)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
* Bump brakeman from 4.8.2 to 4.9.0 (Update vendor/cache)
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Bump @babel/core from 7.11.0 to 7.11.1 (#9693)
Bumps [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) from 7.11.0 to 7.11.1.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.11.1/packages/babel-core)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Bump preact from 10.4.6 to 10.4.7 (#9696)
Bumps [preact](https://github.com/preactjs/preact) from 10.4.6 to 10.4.7.
- [Release notes](https://github.com/preactjs/preact/releases)
- [Commits](https://github.com/preactjs/preact/compare/10.4.6...10.4.7)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Enable Rubocop 0.89 cops and fix Lint/ violations (#9709)
* Enable new Lint/ cops and run rubocop -a
* Fixing last remaining things with rubocop -a
* Enable and fix Style/ExplicitBlockArgument and Style/GlobalStdStream
* Forgot parenthesis
* changed variable name from article to commentable
* [deploy] Bug Fix:Dont Set Active Channel if ChatChannel Does Not Exist (#9704)
* Rubocop: Enable and fix Style/OptionalBooleanParameter cop (#9711)
* Enable and fix Style/OptionalBooleanParameter cop
* Keep regular parameters for workers
* Keep regular parameters for workers
* Fix spec
* Trigger Travis correctly
* Fix Netlify catch all redirections (#9717)
* added test for get comments by podcast episode
* [deploy] Upgrade Chartkick to fix CVE-2020-16254 Vulnerability (#9718)
* [deploy] Redirect /internal to /admin (#9716)
* Update docs with details on where to install Elasticsearch (#9670) [deploy]
* Gitignore elasticsearch installations
* Add a note to explain that ES should be installed at the root level
Remove `/elasticsearch/*` from .gitignore as well!
* Update reference to home directory in mac + windows installation guides
* [deploy] Improve clean up of user language settings (#9671)
* modified index to allow retreival of comments belonging to either articles or podcast episodes
* updated comments section in api documentation to include info on podcast comments
* changed variable name from article to commentable
* added test for get comments by podcast episode
* added new parameter p_id to safe parameters
* modified index to allow retreival of comments belonging to either articles or podcast episodes
* changed variable name from article to commentable
* Trigger Travis correctly
Co-authored-by: Ben Halpern <bendhalpern@gmail.com>
Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>
Co-authored-by: Josh Puetz <joshpuetz@gmail.com>
Co-authored-by: Andy Zhao <17884966+Zhao-Andy@users.noreply.github.com>
Co-authored-by: Jan Klimo <jan.klimo@gmail.com>
Co-authored-by: Molly Struve <mollylbs@gmail.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: rhymes <rhymes@hey.com>
Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
Co-authored-by: Alex <alexandersmith223@gmail.com>
51 lines
1.9 KiB
Ruby
51 lines
1.9 KiB
Ruby
module Api
|
|
module V0
|
|
class CommentsController < ApiController
|
|
before_action :set_cache_control_headers, only: %i[index show]
|
|
|
|
ATTRIBUTES_FOR_SERIALIZATION = %i[
|
|
id processed_html user_id ancestry deleted hidden_by_commentable_user
|
|
].freeze
|
|
private_constant :ATTRIBUTES_FOR_SERIALIZATION
|
|
|
|
def index
|
|
commentable = params[:a_id] ? Article.find(params[:a_id]) : PodcastEpisode.find(params[:p_id])
|
|
|
|
@comments = commentable.comments
|
|
.includes(:user)
|
|
.select(ATTRIBUTES_FOR_SERIALIZATION)
|
|
.arrange
|
|
|
|
set_surrogate_key_header commentable.record_key, Comment.table_key, edge_cache_keys(@comments)
|
|
end
|
|
|
|
def show
|
|
tree_with_root_comment = Comment.subtree_of(params[:id].to_i(26))
|
|
.includes(:user)
|
|
.select(ATTRIBUTES_FOR_SERIALIZATION)
|
|
.arrange
|
|
|
|
# being only one tree we know that the root comment is the first (and only) key
|
|
@comment = tree_with_root_comment.keys.first
|
|
@comments = tree_with_root_comment[@comment]
|
|
|
|
set_surrogate_key_header Comment.table_key, edge_cache_keys(tree_with_root_comment)
|
|
end
|
|
|
|
private
|
|
|
|
# ancestry wraps a single or multiple trees of comments into a single hash,
|
|
# in the case of an article comments, the hash has multiple keys (the root comments),
|
|
# in the case of a comment and its descendants, the hash has only one key.
|
|
# Either way, we need to use recursion to extract all the comment cache keys
|
|
# collecting both the keys of each level of root comments and their descendants
|
|
# NOTE: the objects are already loaded in memory by "ancestry",
|
|
# so no additional SQL query is performed during this extraction, avoiding N+1s
|
|
def edge_cache_keys(comments_trees)
|
|
comments_trees.keys.flat_map do |comment|
|
|
Array.wrap(comment.record_key) + edge_cache_keys(comments_trees[comment])
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|