Permalink
Browse files

Use Mongoid#unit_of_work to disable identity_map when adding activity…

… to feeds if able
  • Loading branch information...
1 parent b999394 commit 3edfe1cb7488e0833fccd08a92fc6c877f5ab66c @bdmac committed Aug 23, 2012
Showing with 30 additions and 10 deletions.
  1. +30 −10 lib/seymour/channels/feed.rb
@@ -6,18 +6,38 @@ def deliver(activity)
recipients = recipients(activity)
return unless recipients
- if recipients.kind_of?(Mongoid::Criteria)
- # We can only work with Criteria in batches
- batch_size = ::Seymour::Config.feed_batch_size
- 0.step(recipients.count, batch_size) do |offset|
- recipients.limit(batch_size).skip(offset).each do |recipient|
- recipient.add_activity_to_feed!(activity) unless recipient.id.to_s == actor_id
+ begin
+ Mongoid.unit_of_work(disable: :all) do
+ if recipients.kind_of?(Mongoid::Criteria)
+ # We can only work with Criteria in batches
+ batch_size = ::Seymour::Config.feed_batch_size
+ 0.step(recipients.count, batch_size) do |offset|
+ recipients.limit(batch_size).skip(offset).each do |recipient|
+ recipient.add_activity_to_feed!(activity) unless recipient.id.to_s == actor_id
+ end
+ end
+ else
+ # Anything else we get for recipients must respond to each
+ recipients.each do |recipient|
+ recipient.add_activity_to_feed!(activity) unless recipient.id.to_s == actor_id
+ end
end
end
- else
- # Anything else we get for recipients must respond to each
- recipients.each do |recipient|
- recipient.add_activity_to_feed!(activity) unless recipient.id.to_s == actor_id
+ rescue ArgumentError
+ # We're using a non-patched version of Mongoid without a way to disable identity map.
+ if recipients.kind_of?(Mongoid::Criteria)
+ # We can only work with Criteria in batches
+ batch_size = ::Seymour::Config.feed_batch_size
+ 0.step(recipients.count, batch_size) do |offset|
+ recipients.limit(batch_size).skip(offset).each do |recipient|
+ recipient.add_activity_to_feed!(activity) unless recipient.id.to_s == actor_id
+ end
+ end
+ else
+ # Anything else we get for recipients must respond to each
+ recipients.each do |recipient|
+ recipient.add_activity_to_feed!(activity) unless recipient.id.to_s == actor_id
+ end
end
end
end

0 comments on commit 3edfe1c

Please sign in to comment.