diff options
author | Johan Sørensen <johan@johansorensen.com> | 2009-12-09 17:11:23 +0100 |
---|---|---|
committer | Johan Sørensen <johan@johansorensen.com> | 2009-12-09 17:11:23 +0100 |
commit | eea615b20478b5e8b38865f7ac988008da2bc7bd (patch) | |
tree | bc60d39bf411fc0ab9b7656c3568f611d57fda6f | |
parent | db78e9fbc83a95462701f080791c5b926a34fa6a (diff) | |
download | gitorious-mainline-outdated-eea615b20478b5e8b38865f7ac988008da2bc7bd.zip gitorious-mainline-outdated-eea615b20478b5e8b38865f7ac988008da2bc7bd.tar.gz gitorious-mainline-outdated-eea615b20478b5e8b38865f7ac988008da2bc7bd.tar.bz2 |
Move the bulk creation of feed items into the FeedItem class
-rwxr-xr-x | app/models/event.rb | 15 | ||||
-rw-r--r-- | app/models/feed_item.rb | 11 |
2 files changed, 14 insertions, 12 deletions
diff --git a/app/models/event.rb b/app/models/event.rb index 287c5d2..e6f434f 100755 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -127,21 +127,12 @@ class Event < ActiveRecord::Base def create_feed_items return if self.action == Action::COMMIT - watcher_ids = find_watcher_ids - return if watcher_ids.blank? - - # Build a FeedItem for all the users interested in this events - sql_values = watcher_ids.map do |an_id| - "(#{an_id}, #{self.id}, '#{self.created_at.to_s(:db)}', '#{self.created_at.to_s(:db)}')" - end - sql = %Q{INSERT INTO feed_items (watcher_id, event_id, created_at, updated_at) - VALUES #{sql_values.join(',')}} - ActiveRecord::Base.connection.execute(sql) + FeedItem.bulk_create_from_watcher_list_and_event!(watcher_ids, self) end protected - def find_watcher_ids - # Find all the watchers of the project + def watcher_ids + # Find all the watchers of the project watcher_ids = self.project.watchers.find(:all, :select => "users.id").map(&:id) # Find anyone who's just watching the target, if it's watchable if self.target.respond_to?(:watchers) diff --git a/app/models/feed_item.rb b/app/models/feed_item.rb index e3d47cf..6b8eda0 100644 --- a/app/models/feed_item.rb +++ b/app/models/feed_item.rb @@ -20,4 +20,15 @@ class FeedItem < ActiveRecord::Base belongs_to :event belongs_to :watcher, :class_name => "User" + def self.bulk_create_from_watcher_list_and_event!(watcher_ids, event) + return if watcher_ids.blank? + # Build a FeedItem for all the watchers interested in the event + sql_values = watcher_ids.map do |an_id| + "(#{an_id}, #{event.id}, '#{event.created_at.to_s(:db)}', '#{event.created_at.to_s(:db)}')" + end + sql = %Q{INSERT INTO feed_items (watcher_id, event_id, created_at, updated_at) + VALUES #{sql_values.join(',')}} + ActiveRecord::Base.connection.execute(sql) + end + end |