diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-03-16 14:52:45 +0300 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-03-16 14:52:55 +0300 |
commit | 09ef69b7c8e534cedff2ca1a42b58f534e349107 (patch) | |
tree | dcccbd830331c7c7558f57cae349f18ebd0b5e7c | |
parent | 9698b36c1cd0808adb006593c0e8649cb42f3571 (diff) |
code folding fix
-rw-r--r-- | app/models/concerns/issuable.rb | 6 | ||||
-rw-r--r-- | app/models/subscribe.rb | 3 | ||||
-rw-r--r-- | app/services/notification_service.rb | 10 | ||||
-rw-r--r-- | db/migrate/20150313012111_create_subscribes_table.rb | 4 | ||||
-rw-r--r-- | db/schema.rb | 4 |
5 files changed, 19 insertions, 8 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index e89dcbf9acb..c74d9cb9917 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -134,9 +134,9 @@ module Issuable end def subscribe_status(user) - sub = subscribes.find_by_user_id(user.id) - if sub - return sub.subscribed + subscribe = subscribes.find_by_user_id(user.id) + if subscribe + return subscribe.subscribed end participants.include?(user) diff --git a/app/models/subscribe.rb b/app/models/subscribe.rb index a68546667f1..be8b9e7605d 100644 --- a/app/models/subscribe.rb +++ b/app/models/subscribe.rb @@ -1,3 +1,6 @@ class Subscribe < ActiveRecord::Base belongs_to :user + + validates :issue_id, uniqueness: { scope: :user_id, allow_nil: true } + validates :merge_request_id, uniqueness: { scope: :user_id, allow_nil: true } end diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 4fa775a28ce..edfb62a4b18 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -368,16 +368,16 @@ class NotificationService recipients = reject_muted_users(recipients, project) recipients = reject_mention_users(recipients, project) - recipients = add_subscribers(recipients, project) + recipients = add_subscribed_users(recipients, project) recipients = recipients.concat(project_watchers(project)).uniq recipients = reject_unsubscribed_users(recipients, target) recipients end - def add_subscribers(recipients, target) - subs = target.subscribes - if subs.any? - recipients.merge(subs.where("subscribed is true").map(&:user)) + def add_subscribed_users(recipients, target) + subscribes = target.subscribes + if subscribes.any? + recipients.merge(subscribes.where("subscribed is true").map(&:user)) else recipients end diff --git a/db/migrate/20150313012111_create_subscribes_table.rb b/db/migrate/20150313012111_create_subscribes_table.rb index 706cf77118c..ab0e9a2a5b5 100644 --- a/db/migrate/20150313012111_create_subscribes_table.rb +++ b/db/migrate/20150313012111_create_subscribes_table.rb @@ -8,5 +8,9 @@ class CreateSubscribesTable < ActiveRecord::Migration t.timestamps end + + add_index :subscribes, :user_id + add_index :subscribes, :issue_id + add_index :subscribes, :merge_request_id end end diff --git a/db/schema.rb b/db/schema.rb index 6afb79069e4..46663ad495b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -406,6 +406,10 @@ ActiveRecord::Schema.define(version: 20150313012111) do t.datetime "updated_at" end + add_index "subscribes", ["issue_id"], name: "index_subscribes_on_issue_id", using: :btree + add_index "subscribes", ["merge_request_id"], name: "index_subscribes_on_merge_request_id", using: :btree + add_index "subscribes", ["user_id"], name: "index_subscribes_on_user_id", using: :btree + create_table "taggings", force: true do |t| t.integer "tag_id" t.integer "taggable_id" |