#79 √ resolved
Michael Hartl

Feed item generation is slow

Reported by Michael Hartl | May 23rd, 2008 @ 06:15 PM | in Foundations

Making all the activity feed items for a user with many contacts (such as Michael Hartl at Insoshi) is really slow. (Among other things, this makes registration slow, since new people get connected to the admin by default, and that connection goes into the admin's feed.)

The culprit is the code in lib/activity_logger.rb:

  def add_activities(options = {})
    person = options[:person]
    include_person = options[:include_person]
    activity = options[:activity] ||
               Activity.create!(:item => options[:item], :person => person)
    person.contacts.each do |c|
      # Prevent duplicate entries in the feed.
      c.activities << activity unless c.activities.include?(activity)
    end
    if include_person
      person.activities << activity unless person.activities.include?(activity)
    end
  end

I suspect there's some sort of awful O(n2) explosion here. We need to fix it.

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket