[refs #265] fixed subscribe dublicates
This commit is contained in:
parent
ecfb4f81a0
commit
5b932879e2
|
@ -33,7 +33,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
|||
|
||||
when 'Comment'
|
||||
if record.commentable.class == Issue
|
||||
subscribes = record.commentable.subscribes.finder_hack
|
||||
subscribes = record.commentable.subscribes
|
||||
subscribes.each do |subscribe|
|
||||
if record.user_id != subscribe.user_id
|
||||
UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe)
|
||||
|
|
|
@ -73,8 +73,9 @@ class Issue < ActiveRecord::Base
|
|||
def subscribe_users
|
||||
recipients = collect_recipient_ids
|
||||
recipients.each do |recipient_id|
|
||||
ss = self.subscribes.build(:user_id => recipient_id)
|
||||
ss.save!
|
||||
if User.find(recipient_id).notifier.new_comment && !self.subscribes.exists?(:user_id => recipient_id)
|
||||
ss = self.subscribes.create(:user_id => recipient_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@ class Subscribe < ActiveRecord::Base
|
|||
belongs_to :user
|
||||
belongs_to :project
|
||||
|
||||
scope :finder_hack, order('') # FIXME .subscribes - error; .subscribes.finder_hack - success Oo
|
||||
|
||||
def commit_subscribe?
|
||||
subscribeable_type == 'Grit::Commit'
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
class DeleteDublicateSubscribes < ActiveRecord::Migration
|
||||
def up
|
||||
execute <<-SQL
|
||||
DELETE FROM subscribes s
|
||||
WHERE s.id NOT IN (SELECT MIN(s1.id) FROM SUBSCRIBES s1
|
||||
GROUP BY s1.subscribeable_type, s1.user_id, s1.status, s1.subscribeable_id)
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue