vrfs774: fixed bug in latlng/distance when city param used; added M_MILES_DEFAULT; changed value of PARAM_MUSICIAN

This commit is contained in:
Jonathan Kolyer 2013-11-23 06:16:40 -06:00
parent 58bed4bc04
commit 1941c65b66
1 changed files with 11 additions and 12 deletions

View File

@ -83,9 +83,10 @@ module JamRuby
attr_accessor :user_counters, :page_num, :page_count
PARAM_MUSICIAN = :search_m
PARAM_MUSICIAN = :srch_m
M_PER_PAGE = 10
M_MILES_DEFAULT = 500
M_ORDER_FOLLOWS = ['Most Followed', :followed]
M_ORDER_PLAYS = ['Most Plays', :plays]
@ -106,14 +107,13 @@ module JamRuby
end
location_distance, location_city = params[:distance], params[:city]
distance, latlng = nil, []
if location_distance && location_city
if geo = MaxMindGeo.where(:city => params[:city]).limit(1).first
citylatlng = [geo.lat, geo.lng]
rel = rel.within(location_distance, :origin => citylatlng)
distance, latlng = location_distance, [geo.lat, geo.lng]
end
elsif current_user
latlng = []
if current_user.lat.nil?
if current_user.lat.nil? || current_user.lng.nil?
if params[:remote_ip]
if geo = MaxMindGeo.ip_lookup(params[:remote_ip])
latlng = [geo.lat, geo.lng] if geo.lat && geo.lng
@ -122,13 +122,12 @@ module JamRuby
else
latlng = [current_user.lat, current_user.lng]
end
distance = location_distance || 50
unless latlng.blank?
rel = rel.where(['lat IS NOT NULL AND lng IS NOT NULL'])
.within(distance, :origin => latlng)
end
distance = location_distance || M_MILES_DEFAULT
end
unless latlng.blank?
rel = rel.where(['lat IS NOT NULL AND lng IS NOT NULL'])
.within(distance, :origin => latlng)
end
sel_str = 'users.*'
case ordering = self.musician_order_param(params)
when :plays
@ -247,7 +246,7 @@ module JamRuby
false
end
def self.new_musicians(since_date=Time.now - 1.week, max_count=100, radius=500)
def self.new_musicians(since_date=Time.now - 1.week, max_count=100, radius=M_MILES_DEFAULT)
return unless block_given?
User.where(['lat IS NOT NULL AND lng IS NOT NULL']).find_each do |usr|
rel = User.musicians