projects
/
rails.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9f17066
)
Use home_tile to find nearby users
author
Tom Hughes
<tom@compton.nu>
Sun, 4 Feb 2018 16:03:16 +0000
(16:03 +0000)
committer
Tom Hughes
<tom@compton.nu>
Sun, 4 Mar 2018 09:59:24 +0000
(09:59 +0000)
app/models/user.rb
patch
|
blob
|
history
diff --git
a/app/models/user.rb
b/app/models/user.rb
index 2a6351e5024b428a9fc3674b9375067558b2167f..d7cd8c8b83d4e7d31466f657ff9883a95406b6fb 100644
(file)
--- a/
app/models/user.rb
+++ b/
app/models/user.rb
@@
-190,8
+190,14
@@
class User < ActiveRecord::Base
def nearby(radius = NEARBY_RADIUS, num = NEARBY_USERS)
if home_lon && home_lat
gc = OSM::GreatCircle.new(home_lat, home_lon)
def nearby(radius = NEARBY_RADIUS, num = NEARBY_USERS)
if home_lon && home_lat
gc = OSM::GreatCircle.new(home_lat, home_lon)
+ sql_for_area = QuadTile.sql_for_area(gc.bounds(radius), "home_")
sql_for_distance = gc.sql_for_distance("home_lat", "home_lon")
sql_for_distance = gc.sql_for_distance("home_lat", "home_lon")
- nearby = User.where("id != ? AND status IN (\'active\', \'confirmed\') AND data_public = ? AND #{sql_for_distance} <= ?", id, true, radius).order(sql_for_distance).limit(num)
+ nearby = User.active.identifiable
+ .where("id != ?", id)
+ .where(sql_for_area)
+ .where("#{sql_for_distance} <= ?", radius)
+ .order(sql_for_distance)
+ .limit(num)
else
nearby = []
end
else
nearby = []
end