Fixed city caching
This commit is contained in:
parent
e83c2fc464
commit
185c521f15
4
Rakefile
4
Rakefile
@ -37,8 +37,8 @@ task update_cities: :environment do
|
||||
end
|
||||
end
|
||||
|
||||
unless c.place_id.present?
|
||||
City.all.each do |c|
|
||||
City.all.each do |c|
|
||||
unless c.place_id.present?
|
||||
location = Geocoder.search(c.address, language: 'en').first
|
||||
c.place_id = location.data['place_id']
|
||||
c.save!
|
||||
|
@ -66,7 +66,7 @@ class City < ActiveRecord::Base
|
||||
|
||||
# return the city if we found it in the db already
|
||||
if city.present?
|
||||
CityCache.create(city_id: city.id, search: str)
|
||||
CityCache.cache(str, city.id)
|
||||
return city
|
||||
end
|
||||
|
||||
@ -119,7 +119,7 @@ class City < ActiveRecord::Base
|
||||
# and not an address or country
|
||||
# some places are not labeled 'locality', search for 'Halifax NS' for example and you will
|
||||
# get 'administrative_area_level_2' since Halifax is a municipality
|
||||
if component['types'] == location.data['types'] && not_a_city.include?(component['types'].first)
|
||||
if component['types'] == location.data['types'] && !not_a_city.include?(component['types'].first)
|
||||
searched_component = component['short_name']
|
||||
end
|
||||
end
|
||||
@ -135,7 +135,7 @@ class City < ActiveRecord::Base
|
||||
city.save!
|
||||
|
||||
# save this to our cache
|
||||
CityCache.create(city_id: city.id, search: str)
|
||||
CityCache.cache(str, city.id)
|
||||
|
||||
# and return it
|
||||
return city
|
||||
|
@ -6,4 +6,8 @@ class CityCache < ActiveRecord::Base
|
||||
def self.search(str)
|
||||
CityCache.find_by_search(str.downcase)
|
||||
end
|
||||
|
||||
def self.cache(str, city_id)
|
||||
CityCache.create(city_id: city_id, search: str.downcase)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user