only flush ip info occasionally
This commit is contained in:
parent
c65b465560
commit
6d6c2d52cd
|
@ -194,14 +194,19 @@ async def sync_database(db, opts: Options):
|
||||||
|
|
||||||
|
|
||||||
async def locate_ips(db, opts: Options):
|
async def locate_ips(db, opts: Options):
|
||||||
|
from time import time
|
||||||
seen = set()
|
seen = set()
|
||||||
|
last_save = time()
|
||||||
while (ip := await opts.ips.get()) is not None:
|
while (ip := await opts.ips.get()) is not None:
|
||||||
if opts.ipinfo is not None and ip not in seen:
|
if opts.ipinfo is not None and ip not in seen:
|
||||||
seen.add(ip)
|
seen.add(ip)
|
||||||
code = await opts.ipinfo.find_country(ip)
|
code = await opts.ipinfo.find_country(ip)
|
||||||
if db is not None:
|
if db is not None:
|
||||||
db.modify_address(ip, country_code=code)
|
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):
|
async def main(db, filepaths, checks, opts: Options):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user