raw1z / amistad

Adds friendships management into a rails application
http://github.com/raw1z/amistad
MIT License
185 stars 71 forks source link

About query and performance #42

Open soyoh opened 11 years ago

soyoh commented 11 years ago

Hello, first of all, thanks for your work, is a nice gem, i'm plaining to use it in several projects im planing.

just playing with it on the console, i find that there are too much querys, heres is an example.

1) user A invites user B 2) user B accepts user A invitation

userB.appove(userA)

this method, located at active_record_friend_model (:67) use another method to find if there is a friendship record between these two users "find_any_friendship_with(userA)" but, under this line, there is another mehod that do the same "invited?(:156)" that also uses "find_any_friendship_with", what about if we just do one query?? maybe the method can just be like this:

  def approve(user)
    friendship = find_any_friendship_with(user)
    return false if friendship.nil?
    friendship.update_attribute(:pending, false)
  end

i'm new on ruby, maybe i'm missing something....

thanks!!!