]> git.openstreetmap.org Git - rails.git/commitdiff
Use home_tile to find nearby users
authorTom Hughes <tom@compton.nu>
Sun, 4 Feb 2018 16:03:16 +0000 (16:03 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 4 Mar 2018 09:59:24 +0000 (09:59 +0000)
app/models/user.rb

index 2a6351e5024b428a9fc3674b9375067558b2167f..d7cd8c8b83d4e7d31466f657ff9883a95406b6fb 100644 (file)
@@ -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)
+      sql_for_area = QuadTile.sql_for_area(gc.bounds(radius), "home_")
       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