From 6d6c2d52cda3a982eb5c1e7875e09cbe32d8af8b Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 5 Sep 2020 04:09:21 +0200 Subject: [PATCH] only flush ip info occasionally --- respodns/dns.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/respodns/dns.py b/respodns/dns.py index 026a780..c5a8d4b 100644 --- a/respodns/dns.py +++ b/respodns/dns.py @@ -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):