Guest User

Untitled

a guest
Apr 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. # Clear out older inconsistencies (like multiple invitations)
  2. def self.ensure_consistent
  3. sorted = Invite.find(:all, :order => 'user_id ASC, inviter_id ASC, created_at ASC')
  4.  
  5. skip_ids = [] # Not sure if this is necessary, but it works and not worth testing without
  6. sorted.each_with_index do |curr, index|
  7. break if index+1 == sorted.size
  8. next if skip_ids.include?(curr.id)
  9. nxt = sorted[index+1]
  10. if curr.user_id == nxt.user_id && curr.inviter_id == nxt.inviter_id
  11. skip_ids << curr.id
  12. curr.destroy # Rely on sorting of invitation type - ends with deleting all but most recent
  13. end
  14. end
  15. end
Add Comment
Please, Sign In to add comment