Skip to content
Snippets Groups Projects
Commit 339cd14d authored by Alex Reisner's avatar Alex Reisner
Browse files

Merge pull request #704 from gersmann/master

Refactor SQL statement to prevent table join
parents 2947fbd6 1adfe8f9
No related branches found
No related tags found
No related merge requests found
......@@ -35,8 +35,8 @@ module Geocoder::Lookup
elsif configuration[:package] == :city
addr = IPAddr.new(query.text).to_i
q = "SELECT l.country, l.region, l.city, l.latitude, l.longitude
FROM maxmind_geolite_city_location l JOIN maxmind_geolite_city_blocks b USING (loc_id)
WHERE b.start_ip_num <= #{addr} AND #{addr} <= b.end_ip_num"
FROM maxmind_geolite_city_location l WHERE l.loc_id = (SELECT b.loc_id FROM maxmind_geolite_city_blocks b
WHERE b.start_ip_num <= #{addr} AND #{addr} <= b.end_ip_num)"
format_result(q, [:country_name, :region_name, :city_name, :latitude, :longitude])
elsif configuration[:package] == :country
addr = IPAddr.new(query.text).to_i
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment