Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Clear out older inconsistencies (like multiple invitations)
- def self.ensure_consistent
- sorted = Invite.find(:all, :order => 'user_id ASC, inviter_id ASC, created_at ASC')
- skip_ids = [] # Not sure if this is necessary, but it works and not worth testing without
- sorted.each_with_index do |curr, index|
- break if index+1 == sorted.size
- next if skip_ids.include?(curr.id)
- nxt = sorted[index+1]
- if curr.user_id == nxt.user_id && curr.inviter_id == nxt.inviter_id
- skip_ids << curr.id
- curr.destroy # Rely on sorting of invitation type - ends with deleting all but most recent
- end
- end
- end
Add Comment
Please, Sign In to add comment