mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 14:19:53 +01:00
Ensure counters only get updated if the record exists
This commit is contained in:
parent
e2462b1e51
commit
539505eccd
5 changed files with 10 additions and 10 deletions
|
@ -28,13 +28,13 @@ class Answer < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
self.user.decrement! :answered_count
|
||||
self.question.decrement! :answer_count
|
||||
self.user&.decrement! :answered_count
|
||||
self.question&.decrement! :answer_count
|
||||
self.smiles.each do |smile|
|
||||
Notification.denotify self.user, smile
|
||||
end
|
||||
self.comments.each do |comment|
|
||||
comment.user.decrement! :commented_count
|
||||
comment.user&.decrement! :commented_count
|
||||
Subscription.denotify comment, self
|
||||
end
|
||||
Notification.denotify self.question.user, self
|
||||
|
|
|
@ -10,8 +10,8 @@ class Appendable::Reaction < Appendable
|
|||
|
||||
before_destroy do
|
||||
Notification.denotify parent.user, self
|
||||
user.decrement! :smiled_count
|
||||
parent.decrement! :smile_count
|
||||
user&.decrement! :smiled_count
|
||||
parent&.decrement! :smile_count
|
||||
end
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ class Comment < ApplicationRecord
|
|||
end
|
||||
|
||||
Subscription.denotify self, answer
|
||||
user.decrement! :commented_count
|
||||
answer.decrement! :comment_count
|
||||
user&.decrement! :commented_count
|
||||
answer&.decrement! :comment_count
|
||||
end
|
||||
|
||||
def notification_type(*_args)
|
||||
|
|
|
@ -16,7 +16,7 @@ class Question < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
user.decrement! :asked_count unless self.author_is_anonymous
|
||||
user&.decrement! :asked_count unless self.author_is_anonymous
|
||||
end
|
||||
|
||||
def can_be_removed?
|
||||
|
|
|
@ -45,8 +45,8 @@ class User < ApplicationRecord
|
|||
has_many :subscriptions, dependent: :destroy_async
|
||||
has_many :totp_recovery_codes, dependent: :destroy_async
|
||||
|
||||
has_one :profile, dependent: :destroy_async
|
||||
has_one :theme, dependent: :destroy_async
|
||||
has_one :profile, dependent: :destroy
|
||||
has_one :theme, dependent: :destroy
|
||||
|
||||
has_many :bans, class_name: "UserBan", dependent: :destroy_async
|
||||
has_many :banned_users, class_name: 'UserBan',
|
||||
|
|
Loading…
Reference in a new issue