Last active
May 23, 2017 21:54
-
-
Save meltingice/cab55a5a563c383f472f6867ccbb35b4 to your computer and use it in GitHub Desktop.
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
# If the comment tree exists in cache, it will be pulled from cache without | |
# doing any extra processing. If it doesn't exist in cache, we do all of the | |
# stuff I wrote about above. | |
data = Rails.cache.fetch(Comment.cache_key_for(@article, @params[:sort])) do | |
arranged_comments.map do |data| | |
# Each data object contains the comment, it's reply_to (if applicable), and | |
# the comment children. Calling as_json will convert all of the data to a | |
# plain JSON-like object. | |
Api::V1::CommentSerializer.new(data).as_json | |
end | |
end | |
# Once we have the comment data structure, we can pass it along to the decorator! | |
CommentDecoratorService.new(@article, data, current_member: @current_member).decorate! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment