Class: UserStatCountUpdater

Inherits:
Object
  • Object
show all
Defined in:
app/services/user_stat_count_updater.rb

Class Method Summary collapse

Class Method Details

.decrement!(post, user_stat: nil) ⇒ Object



9
10
11
# File 'app/services/user_stat_count_updater.rb', line 9

def decrement!(post, user_stat: nil)
  update_using_operator!(post, user_stat: user_stat, action: :decrement!)
end

.increment!(post, user_stat: nil) ⇒ Object



5
6
7
# File 'app/services/user_stat_count_updater.rb', line 5

def increment!(post, user_stat: nil)
  update_using_operator!(post, user_stat: user_stat, action: :increment!)
end

.set!(user_stat:, count:, count_column:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/user_stat_count_updater.rb', line 13

def set!(user_stat:, count:, count_column:)
  return if user_stat.blank?
  return if !%i[post_count topic_count].include?(count_column)

  if SiteSetting.verbose_user_stat_count_logging && count < 0
    Rails.logger.warn(
      "Attempted to insert negative count into UserStat##{count_column} for user #{user_stat.user_id}, using 0 instead. Caller:\n #{caller[0..10].join("\n")}",
    )
  end

  user_stat.update_column(count_column, [count, 0].max)
end