Files
danbooru/app/views/comments/index.atom.builder
evazion 59b277ead1 users: drop id_to_name, name_to_id caching.
Changes:

* Drop Users.id_to_name.
* Don't cache Users.name_to_id.
* Replace calls to name_to_id with find_by_name when possible.
* Don't autodefine creator_name in belongs_to_creator.
* Don't autodefine updater_name in belongs_to_updater.
* Instead manually define creator_name / updater_name only on models that need
  to return these fields in the api.

id_to_name was cached to reduce the impact of N+1 query patterns in
certain places, especially in api responses that return creator_name /
updater_name fields. But it still meant we were doing N calls to
memcache. Using `includes` to prefetch users avoids this N+1 pattern.

name_to_id had no need be cached, it was never used in any performance-
sensitive contexts.

Avoiding caching also avoids the need to keep these caches consistent.
2019-08-18 11:24:42 -05:00

26 lines
1.0 KiB
Ruby

atom_feed(root_url: comments_url(host: Danbooru.config.hostname)) do |feed|
title = "Comments"
title += " by #{params[:search][:creator_name]}" if params.dig(:search, :creator_name).present?
title += " on #{params[:search][:post_tags_match]}" if params.dig(:search, :post_tags_match).present?
title += " on post ##{params[:search][:post_id]}" if params.dig(:search, :post_id).present?
feed.title(title)
feed.updated(@comments.first.try(:updated_at))
@comments.each do |comment|
feed.entry(comment, published: comment.created_at, updated: comment.updated_at) do |entry|
entry.title("@#{comment.creator.name} on post ##{comment.post_id} (#{comment.post.presenter.humanized_essential_tag_string})")
entry.content(<<-EOS.strip_heredoc, type: "html")
<img src="#{comment.post.preview_file_url}"/>
#{format_text(comment.body)}
EOS
entry.author do |author|
author.name(comment.creator.name)
author.uri(user_url(comment.creator))
end
end
end
end