Move rescoring concerns to bubble
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class Bubble < ApplicationRecord
|
||||
include Assignable, Boostable, Colored, Eventable, Messages, Poppable, Searchable, Staged, Taggable
|
||||
include Assignable, Boostable, Colored, Commentable, Eventable, Messages, Poppable, Searchable, Staged, Taggable
|
||||
|
||||
belongs_to :bucket, touch: true
|
||||
belongs_to :creator, class_name: "User", default: -> { Current.user }
|
||||
@@ -11,7 +11,6 @@ class Bubble < ApplicationRecord
|
||||
scope :reverse_chronologically, -> { order created_at: :desc, id: :desc }
|
||||
scope :chronologically, -> { order created_at: :asc, id: :asc }
|
||||
scope :ordered_by_activity, -> { order activity_score: :desc }
|
||||
scope :ordered_by_comments, -> { order comments_count: :desc }
|
||||
scope :in_bucket, ->(bucket) { where bucket: bucket }
|
||||
|
||||
scope :indexed_by, ->(index) do
|
||||
|
||||
@@ -7,9 +7,9 @@ module Bubble::Boostable
|
||||
|
||||
def boost!
|
||||
transaction do
|
||||
track_event :boosted
|
||||
increment! :boost_count
|
||||
rescore
|
||||
track_event :boosted
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
module Bubble::Commentable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
scope :ordered_by_comments, -> { order comments_count: :desc }
|
||||
end
|
||||
|
||||
def comment_captured
|
||||
increment! :comments_count
|
||||
rescore
|
||||
end
|
||||
|
||||
def comment_uncaptured
|
||||
decrement! :comments_count
|
||||
rescore
|
||||
end
|
||||
end
|
||||
@@ -6,12 +6,10 @@ class Comment < ApplicationRecord
|
||||
searchable_by :body, using: :comments_search_index
|
||||
|
||||
def captured_as(message)
|
||||
message.bubble.increment! :comments_count
|
||||
message.bubble.rescore
|
||||
message.bubble.comment_captured
|
||||
end
|
||||
|
||||
def uncaptured_as(message)
|
||||
message.bubble.decrement! :comments_count
|
||||
message.bubble.rescore
|
||||
message.bubble.comment_uncaptured
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user