docbrown/app/controllers/moderations_controller.rb
rhymes 6a626e819d Refactor: fix issues raised by bullet (#2965)
* Preload organization, not user

* Preload users only when needed

* Pre-load podcasts for podcast episodes in API

* Avoid eager loading error by loading rating votes separately

* Preload associations for moderation

* Preload user comments in trees

* Preload organization for non org dashboard and cleanup queries

* Optimize ArticleSuggester to only load N articles at need

* Remove eager loading and pass variables to partials for easier debug

* Reorganize tags validation code and ignore actsastaggableon eager loading issues

* Remove unused eager loading and bring up comments relation

* Preload podcasts when loading podcast episodes

* Fix views specs

* Make sure ArticleSuggester never returns duplicates

* Remove commented code

* Re-trigger build

* Move suggested articles back to view to respect fragment caching
2019-05-28 17:32:53 -04:00

29 lines
844 B
Ruby

class ModerationsController < ApplicationController
after_action :verify_authorized
def index
skip_authorization
return unless current_user&.trusted
@articles = Article.published.
where("rating_votes_count < 3").
where("score > -5").
order("hotness_score DESC").limit(100)
@articles = @articles.cached_tagged_with(params[:tag]) if params[:tag].present?
@rating_votes = RatingVote.where(article: @articles.pluck(:id), user: current_user)
@articles = @articles.decorate
end
def article
authorize(User, :moderation_routes?)
@moderatable = Article.find_by(slug: params[:slug])
render template: "moderations/mod"
end
def comment
authorize(User, :moderation_routes?)
@moderatable = Comment.find(params[:id_code].to_i(26))
render template: "moderations/mod"
end
end