Move rescoring concerns to bubble

This commit is contained in:
Jose Farias
2024-11-15 19:48:53 -06:00
parent 8cd22a7f20
commit f17b060906
4 changed files with 21 additions and 7 deletions
+1 -2
View File
@@ -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
+1 -1
View File
@@ -7,9 +7,9 @@ module Bubble::Boostable
def boost!
transaction do
track_event :boosted
increment! :boost_count
rescore
track_event :boosted
end
end
end
+17
View File
@@ -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
+2 -4
View File
@@ -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