Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comments API: fix caching issues (#4744) [deploy]
* Use ancestry in the index and add test * Add tests for show action * Return complete comments trees for index, kill n+1 and use correct edge cache key * Return complete comments tree for show, kill n+1 and use correct edge cache key * Refactor tests and add surrogate keys tests * Preload users for the whole subtree * Clarify explanation of the edge cache keys construction * Refactor partials * Remove action caching * Replace .map.flatten with .flat_map * Fix surrogate key prefix according to Fastly docs * Add comment.purge to Comments::BustCacheJob to use Fastly-Rails * Fix surrogate key spec
- Loading branch information
1 parent
bbaa590
commit bcd8545
Showing
8 changed files
with
99 additions
and
122 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
json.type_of "comment" | ||
|
||
json.id_code comment.id_code_generated | ||
json.body_html comment.processed_html | ||
|
||
json.partial! "api/v0/shared/user", user: comment.user |
6 changes: 6 additions & 0 deletions
6
app/views/api/v0/comments/_comment_with_children.json.jbuilder
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
json.partial! "comment", comment: comment | ||
|
||
# recursively render the comment subtree | ||
json.children do | ||
json.partial! "comments_with_children", comments: children | ||
end |
4 changes: 4 additions & 0 deletions
4
app/views/api/v0/comments/_comments_with_children.json.jbuilder
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
json.array! comments.keys do |root_comment| | ||
# ancestry organizes root comments and their descendants in a hash structure | ||
json.partial! "comment_with_children", comment: root_comment, children: comments[root_comment] | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1 @@ | ||
json.array! @comments do |comment| | ||
json.type_of "comment" | ||
|
||
json.id_code comment.id_code_generated | ||
json.body_html comment.processed_html | ||
json.user do | ||
json.name comment.user.name | ||
json.username comment.user.username | ||
json.twitter_username comment.user.twitter_username | ||
json.github_username comment.user.github_username | ||
json.website_url comment.user.processed_website_url | ||
json.profile_image ProfileImage.new(comment.user).get(640) | ||
json.profile_image_90 ProfileImage.new(comment.user).get(90) | ||
end | ||
|
||
json.children comment.children.order(score: :desc).each do |children_comment| | ||
json.id_code children_comment.id_code_generated | ||
json.body_html children_comment.processed_html | ||
json.user do | ||
json.name children_comment.user.name | ||
json.username children_comment.user.username | ||
json.twitter_username children_comment.user.twitter_username | ||
json.github_username children_comment.user.github_username | ||
json.website_url children_comment.user.processed_website_url | ||
json.profile_image ProfileImage.new(children_comment.user).get(640) | ||
json.profile_image_90 ProfileImage.new(children_comment.user).get(90) | ||
end | ||
|
||
json.children children_comment.children.order(score: :desc).each do |grandchild_comment| | ||
json.id_code grandchild_comment.id_code_generated | ||
json.body_html grandchild_comment.processed_html | ||
json.user do | ||
json.name grandchild_comment.user.name | ||
json.username grandchild_comment.user.username | ||
json.twitter_username grandchild_comment.user.twitter_username | ||
json.github_username grandchild_comment.user.github_username | ||
json.website_url grandchild_comment.user.processed_website_url | ||
json.profile_image ProfileImage.new(grandchild_comment.user).get(640) | ||
json.profile_image_90 ProfileImage.new(grandchild_comment.user).get(90) | ||
end | ||
end | ||
end | ||
end | ||
json.partial! "comments_with_children", comments: @comments |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1 @@ | ||
json.type_of "comment" | ||
json.id_code @comment.id_code_generated | ||
json.body_html @comment.processed_html | ||
json.user do | ||
json.name @comment.user.name | ||
json.username @comment.user.username | ||
json.twitter_username @comment.user.twitter_username | ||
json.github_username @comment.user.github_username | ||
json.website_url @comment.user.processed_website_url | ||
json.profile_image ProfileImage.new(@comment.user).get(640) | ||
json.profile_image_90 ProfileImage.new(@comment.user).get(90) | ||
end | ||
json.children @comment.children.order("score DESC").each do |children_comment| | ||
json.id_code children_comment.id_code_generated | ||
json.body_html children_comment.processed_html | ||
json.user do | ||
json.name children_comment.user.name | ||
json.username children_comment.user.username | ||
json.twitter_username children_comment.user.twitter_username | ||
json.github_username children_comment.user.github_username | ||
json.website_url children_comment.user.processed_website_url | ||
json.profile_image ProfileImage.new(children_comment.user).get(640) | ||
json.profile_image_90 ProfileImage.new(children_comment.user).get(90) | ||
end | ||
json.children children_comment.children.order("score DESC").each do |grandchild_comment| | ||
json.id_code grandchild_comment.id_code_generated | ||
json.body_html grandchild_comment.processed_html | ||
json.user do | ||
json.name grandchild_comment.user.name | ||
json.username grandchild_comment.user.username | ||
json.twitter_username grandchild_comment.user.twitter_username | ||
json.github_username grandchild_comment.user.github_username | ||
json.website_url grandchild_comment.user.processed_website_url | ||
json.profile_image ProfileImage.new(grandchild_comment.user).get(640) | ||
json.profile_image_90 ProfileImage.new(grandchild_comment.user).get(90) | ||
end | ||
end | ||
end | ||
json.partial! "comment_with_children", comment: @comment, children: @comments |
This file contains 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