Skip to content
Extraits de code Groupes Projets
Valider f3ced6d9 rédigé par danielvincent's avatar danielvincent
Parcourir les fichiers

randomize collections of similar contacts on people#show

parent b4b61893
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -49,13 +49,24 @@ class ApplicationController < ActionController::Base ...@@ -49,13 +49,24 @@ class ApplicationController < ActionController::Base
end end
end end
def similar_people contact def similar_people contact, opts={}
opts[:limit] ||= 5
aspect_ids = contact.aspect_ids aspect_ids = contact.aspect_ids
count = Contact.count(:user_id => current_user.id,
:person_id.ne => contact.person.id,
:aspect_ids.in => aspect_ids)
if count > opts[:limit]
offset = rand(count-opts[:limit])
else
offset = 0
end
contacts = Contact.all(:user_id => current_user.id, contacts = Contact.all(:user_id => current_user.id,
:person_id.ne => contact.person.id, :person_id.ne => contact.person.id,
:aspect_ids.in => aspect_ids, :aspect_ids.in => aspect_ids,
:limit => 5, :skip => offset,
:order => 'updated_at desc') :limit => opts[:limit])
contacts.collect!{ |contact| contact.person } contacts.collect!{ |contact| contact.person }
end end
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter