fix problem where jam_isp importer deleted contents of geoiplocations instead of geoipisp.
This commit is contained in:
parent
a0fab2b584
commit
8072096427
|
|
@ -4,14 +4,14 @@ module JamRuby
|
|||
self.table_name = 'geoipblocks'
|
||||
|
||||
def self.lookup(ipnum)
|
||||
GeoIpBlocks.where('geom && ST_MakePoint(?, 0) AND ? BETWEEN beginip AND endip', ipnum, ipnum)
|
||||
self.where('geom && ST_MakePoint(?, 0) AND ? BETWEEN beginip AND endip', ipnum, ipnum)
|
||||
.limit(1)
|
||||
.first
|
||||
end
|
||||
|
||||
def self.createx(beginip, endip, locid)
|
||||
c = connection.raw_connection
|
||||
c.exec_params('insert into geoipblocks (beginip, endip, locid, geom) values($1::bigint, $2::bigint, $3, ST_MakeEnvelope($1::bigint, -1, $2::bigint, 1))', [beginip, endip, locid])
|
||||
c.exec_params("insert into #{self.table_name} (beginip, endip, locid, geom) values($1::bigint, $2::bigint, $3, ST_MakeEnvelope($1::bigint, -1, $2::bigint, 1))", [beginip, endip, locid])
|
||||
end
|
||||
|
||||
def self.import_from_max_mind(file)
|
||||
|
|
@ -20,8 +20,8 @@ module JamRuby
|
|||
# Format:
|
||||
# startIpNum,endIpNum,locId
|
||||
|
||||
GeoIpBlocks.transaction do
|
||||
GeoIpBlocks.delete_all
|
||||
self.transaction do
|
||||
self.delete_all
|
||||
File.open(file, 'r:ISO-8859-1') do |io|
|
||||
s = io.gets.strip # eat the copyright line. gah, why do they have that in their file??
|
||||
unless s.eql? 'Copyright (c) 2011 MaxMind Inc. All Rights Reserved.'
|
||||
|
|
@ -40,7 +40,7 @@ module JamRuby
|
|||
saved_level = ActiveRecord::Base.logger ? ActiveRecord::Base.logger.level : 0
|
||||
count = 0
|
||||
|
||||
stmt = "insert into #{GeoIpBlocks.table_name} (beginip, endip, locid) values"
|
||||
stmt = "insert into #{self.table_name} (beginip, endip, locid) values"
|
||||
|
||||
vals = ''
|
||||
sep = ''
|
||||
|
|
@ -60,49 +60,49 @@ module JamRuby
|
|||
i += 1
|
||||
|
||||
if count == 0 or i >= n then
|
||||
GeoIpBlocks.connection.execute stmt+vals
|
||||
self.connection.execute stmt+vals
|
||||
count += i
|
||||
vals = ''
|
||||
sep = ''
|
||||
i = 0
|
||||
|
||||
if ActiveRecord::Base.logger and ActiveRecord::Base.logger.level > 1 then
|
||||
ActiveRecord::Base.logger.debug "... logging inserts into #{GeoIpBlocks.table_name} suspended ..."
|
||||
ActiveRecord::Base.logger.debug "... logging inserts into #{self.table_name} suspended ..."
|
||||
ActiveRecord::Base.logger.level = 1
|
||||
end
|
||||
|
||||
if ActiveRecord::Base.logger and count%10000 < n then
|
||||
ActiveRecord::Base.logger.level = saved_level
|
||||
ActiveRecord::Base.logger.debug "... inserted #{count} into #{GeoIpBlocks.table_name} ..."
|
||||
ActiveRecord::Base.logger.debug "... inserted #{count} into #{self.table_name} ..."
|
||||
ActiveRecord::Base.logger.level = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if i > 0 then
|
||||
GeoIpBlocks.connection.execute stmt+vals
|
||||
self.connection.execute stmt+vals
|
||||
count += i
|
||||
end
|
||||
|
||||
if ActiveRecord::Base.logger then
|
||||
ActiveRecord::Base.logger.level = saved_level
|
||||
ActiveRecord::Base.logger.debug "loaded #{count} records into #{GeoIpBlocks.table_name}"
|
||||
ActiveRecord::Base.logger.debug "loaded #{count} records into #{self.table_name}"
|
||||
end
|
||||
|
||||
sts = GeoIpBlocks.connection.execute 'ALTER TABLE geoipblocks DROP COLUMN geom;'
|
||||
sts = self.connection.execute "ALTER TABLE #{self.table_name} DROP COLUMN geom;"
|
||||
ActiveRecord::Base.logger.debug "DROP COLUMN geom returned sts #{sts.cmd_status}" if ActiveRecord::Base.logger
|
||||
# sts.check [we don't care]
|
||||
|
||||
sts = GeoIpBlocks.connection.execute 'ALTER TABLE geoipblocks ADD COLUMN geom geometry(polygon);'
|
||||
sts = self.connection.execute "ALTER TABLE #{self.table_name} ADD COLUMN geom geometry(polygon);"
|
||||
ActiveRecord::Base.logger.debug "ADD COLUMN geom returned sts #{sts.cmd_status}" if ActiveRecord::Base.logger
|
||||
sts.check
|
||||
|
||||
sts = GeoIpBlocks.connection.execute 'UPDATE geoipblocks SET geom = ST_MakeEnvelope(beginip, -1, endip, 1);'
|
||||
sts = self.connection.execute "UPDATE #{self.table_name} SET geom = ST_MakeEnvelope(beginip, -1, endip, 1);"
|
||||
ActiveRecord::Base.logger.debug "SET geom returned sts #{sts.cmd_tuples}" if ActiveRecord::Base.logger
|
||||
sts.check
|
||||
|
||||
sts = GeoIpBlocks.connection.execute 'CREATE INDEX geoipblocks_geom_gix ON geoipblocks USING GIST (geom);'
|
||||
ActiveRecord::Base.logger.debug "CREATE INDEX geoipblocks_geom_gix returned sts #{sts.cmd_status}" if ActiveRecord::Base.logger
|
||||
sts = self.connection.execute "CREATE INDEX #{self.table_name}_geom_gix ON #{self.table_name} USING GIST (geom);"
|
||||
ActiveRecord::Base.logger.debug "CREATE INDEX #{self.table_name}_geom_gix returned sts #{sts.cmd_status}" if ActiveRecord::Base.logger
|
||||
sts.check
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ module JamRuby
|
|||
# Format:
|
||||
# startIpNum,endIpNum,isp
|
||||
|
||||
GeoIpLocations.transaction do
|
||||
GeoIpLocations.delete_all
|
||||
self.transaction do
|
||||
GeoIpIsp.delete_all
|
||||
File.open(file, 'r:ISO-8859-1') do |io|
|
||||
#s = io.gets.strip # eat the copyright line. gah, why do they have that in their file??
|
||||
#unless s.eql? 'Copyright (c) 2012 MaxMind LLC. All Rights Reserved.'
|
||||
|
|
|
|||
Loading…
Reference in New Issue