only flush ip info occasionally

This commit is contained in:
Connor Olding 2020-09-05 04:09:21 +02:00
parent c65b465560
commit 6d6c2d52cd

View file

@ -194,14 +194,19 @@ async def sync_database(db, opts: Options):
async def locate_ips(db, opts: Options):
from time import time
seen = set()
last_save = time()
while (ip := await opts.ips.get()) is not None:
if opts.ipinfo is not None and ip not in seen:
seen.add(ip)
code = await opts.ipinfo.find_country(ip)
if db is not None:
db.modify_address(ip, country_code=code)
opts.ipinfo.flush()
if time() >= last_save + 10.0: # only flush occasionally
opts.ipinfo.flush()
last_save = time()
opts.ipinfo.flush()
async def main(db, filepaths, checks, opts: Options):