Skip to content

Commit

Permalink
Only consider FlagLogs with is_auto=1 for autoflag search
Browse files Browse the repository at this point in the history
Should fix #173
  • Loading branch information
Undo1 committed May 14, 2017
1 parent 5a921cf commit 204c494
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def search_results

case params[:autoflagged].try(:downcase)
when "yes"
@results = @results.includes(:flag_logs).where.not(flag_logs: {id: nil})
@results = @results.autoflagged
when "no"
@results = @results.left_outer_joins(:flag_logs).where(flag_logs: { id: nil })
@results = @results.not_autoflagged
end

respond_to do |format|
Expand Down
8 changes: 8 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class Post < ApplicationRecord
scope :includes_for_post_row, -> { includes(:stack_exchange_user).includes(:reasons).includes(:feedbacks => [:user, :api_key]) }
scope :without_feedback, -> { left_joins(:feedbacks).where( :feedbacks => { :post_id => nil }) }

scope :autoflagged, -> {
includes(:flag_logs).where(flag_logs: { is_auto: true }).where.not(flag_logs: { id: nil })
}

scope :not_autoflagged, -> {
joins('LEFT OUTER JOIN flag_logs ON flag_logs.post_id = posts.id AND flag_logs.is_auto = 0').where(flag_logs: { id: nil })
}

after_create do
ActionCable.server.broadcast "posts_realtime", { row: PostsController.render(locals: {post: Post.last}, partial: 'post').html_safe }
ActionCable.server.broadcast "topbar", { review: Post.without_feedback.count }
Expand Down

0 comments on commit 204c494

Please sign in to comment.