public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Search Repo:
Michael Hartl (author)
Tue May 06 12:48:20 -0700 2008
commit  fa5fb8a6a966eb83862151c4e6861d0b5146e393
tree    bbea8eb8d812f259233160d10ebf1462479bba41
parent  7b1035abd858c865525d74cebc935f96ebe8bb40
insoshi / lib / tasks / feed_undup.rake
100644 20 lines (18 sloc) 0.568 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
require 'active_record'
require 'active_record/fixtures'
 
namespace :feed do
  desc "Remove duplicate feed items"
  task :undup => :environment do |t|
    feed = Feed.find(:all, :order => 'person_id, activity_id')
    dups = []
    feed.each_with_index do |item, i|
      dups.push(item) if i > 0 and same?(item, feed[i-1])
    end
    puts "Destroying #{dups.length} duplicate feed items"
    dups.each { |duplicate| duplicate.destroy }
  end
  
  def same?(item1, item2)
    item1.person_id == item2.person_id &&
    item1.activity_id == item2.activity_id
  end
end