Skip to content

Commit

Permalink
Preventing duplicate activities in the first place
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartl committed May 2, 2008
1 parent d6690c5 commit 1f7f3ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/comment.rb
Expand Up @@ -56,7 +56,7 @@ def commented_person
def log_activity
activity = Activity.create!(:item => self, :person => commenter)
add_activities(:activity => activity, :person => commenter)
unless commented_person.nil?
unless commented_person.nil? or commenter == commented_person
add_activities(:activity => activity, :person => commented_person,
:include_person => true)
end
Expand Down
7 changes: 4 additions & 3 deletions app/models/person.rb
Expand Up @@ -64,8 +64,8 @@ class Person < ActiveRecord::Base
end
has_many :feeds
has_many :activities, :through => :feeds, :order => 'created_at DESC',
:limit => FEED_SIZE,
:uniq => true
:limit => FEED_SIZE# ,
# :uniq => true

validates_presence_of :email, :name
validates_presence_of :password, :if => :password_required?
Expand Down Expand Up @@ -126,11 +126,12 @@ def to_param
# Return a person-specific activity feed.
# TODO: put some algorithms in here to improve feed quality.
def feed
return activities
len = activities.length
if len < FEED_SIZE
# Mix in some global activities for smaller feeds.
global = Activity.global_feed[0...(Activity::GLOBAL_FEED_SIZE-len)]
(activities + global).uniq
(activities + global).uniq#.sort_by { |a| a.created_at}
else
activities
end
Expand Down
8 changes: 6 additions & 2 deletions lib/activity_logger.rb
Expand Up @@ -4,7 +4,11 @@ def add_activities(options = {})
include_person = options[:include_person]
activity = options[:activity] ||
Activity.create!(:item => options[:item], :person => person)
person.contacts.each { |c| c.activities << activity }
person.activities << activity if include_person
person.contacts.each do |c|
c.activities << activity unless c.activities.include?(activity)
end
if include_person
person.activities << activity unless person.activities.include?(activity)
end
end
end

0 comments on commit 1f7f3ac

Please sign in to comment.