From 9361478e74e6d3fcd2b93190dd5af9ce51831173 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 4 Feb 2018 16:03:16 +0000 Subject: [PATCH 1/1] Use home_tile to find nearby users --- app/models/user.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 2a6351e50..d7cd8c8b8 100644 --- 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) + 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 -- 2.43.2