only flush ip info occasionally
This commit is contained in:
parent
c65b465560
commit
6d6c2d52cd
1 changed files with 6 additions and 1 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue