Make IP resolver performance a bit better by skipping an unnecessary set
This will still hang for a second or two on first call
This commit is contained in:
parent
c7baf6cf58
commit
b7d8bb227e
2 changed files with 8 additions and 9 deletions
|
@ -127,12 +127,11 @@ class IPResolver(IPResolverInterface):
|
|||
return None
|
||||
|
||||
sync_token = aws_ip_range_json['syncToken']
|
||||
all_amazon, regions, services = IPResolver._parse_amazon_ranges(aws_ip_range_json)
|
||||
return IPResolver._build_location_function(sync_token, all_amazon, regions, services,
|
||||
self.geoip_db)
|
||||
all_amazon, regions = IPResolver._parse_amazon_ranges(aws_ip_range_json)
|
||||
return IPResolver._build_location_function(sync_token, all_amazon, regions, self.geoip_db)
|
||||
|
||||
@staticmethod
|
||||
def _build_location_function(sync_token, all_amazon, regions, country, country_db):
|
||||
def _build_location_function(sync_token, all_amazon, regions, country_db):
|
||||
@lru_cache(maxsize=4096)
|
||||
def _get_location(ip_address):
|
||||
try:
|
||||
|
@ -167,15 +166,12 @@ class IPResolver(IPResolverInterface):
|
|||
def _parse_amazon_ranges(ranges):
|
||||
all_amazon = IPSet()
|
||||
regions = defaultdict(IPSet)
|
||||
services = defaultdict(IPSet)
|
||||
|
||||
for service_description in ranges['prefixes']:
|
||||
cidr = IPNetwork(service_description['ip_prefix'])
|
||||
service = service_description['service']
|
||||
region = service_description['region']
|
||||
|
||||
all_amazon.add(cidr)
|
||||
regions[region].add(cidr)
|
||||
services[service].add(cidr)
|
||||
|
||||
return all_amazon, regions, services
|
||||
return all_amazon, regions
|
||||
|
|
Reference in a new issue