controllers: refactor only param includes.

Add extra includes needed by the `only` param inside `respond_with`.
This commit is contained in:
evazion
2020-02-14 20:08:42 -06:00
parent 8649ff6dbe
commit 2564e885c8
42 changed files with 153 additions and 387 deletions

View File

@@ -11,7 +11,7 @@ class PostsController < ApplicationController
end
else
@post_set = PostSets::Post.new(tag_query, params[:page], params[:limit], raw: params[:raw], random: params[:random], format: params[:format])
@posts = @post_set.posts = @post_set.posts.includes(model_includes(params)) if !@post_set.is_random?
@posts = @post_set.posts = @post_set.posts.includes(:uploader) if !@post_set.is_random? && CurrentUser.is_moderator?
respond_with(@posts) do |format|
format.atom
end
@@ -98,14 +98,6 @@ class PostsController < ApplicationController
private
def default_includes(params)
if ["json", "xml", "atom"].include?(params[:format])
[]
else
(CurrentUser.user.is_moderator? ? [:uploader] : [])
end
end
def tag_query
params[:tags] || (params[:post] && params[:post][:tags])
end