api/gwinfo and scripts/deletestats: Move gw_netif deletion
Like router stats cleanup the gw_netif table is only cleaned once a day. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
db07af4d8a
commit
4580c46cdb
|
@ -15,7 +15,6 @@ import time
|
|||
def import_gw_data(mysql, gw_data):
|
||||
if "hostname" in gw_data and "netifs" in gw_data:
|
||||
time = utcnow().strftime('%Y-%m-%d %H:%M:%S')
|
||||
threshold = mysql.formatdt(utcnow() - datetime.timedelta(hours=CONFIG["gw_netif_threshold_hours"]))
|
||||
stats_page = gw_data.get("stats_page","")
|
||||
|
||||
if not stats_page:
|
||||
|
@ -61,8 +60,6 @@ def import_gw_data(mysql, gw_data):
|
|||
last_contact=VALUES(last_contact)
|
||||
""",ndata)
|
||||
|
||||
mysql.execute("DELETE FROM gw_netif WHERE last_contact < %s",(threshold,))
|
||||
|
||||
adata = []
|
||||
aid = 0
|
||||
for a in gw_data["admins"]:
|
||||
|
|
|
@ -451,8 +451,9 @@ def delete_stats_helper(mysql,label,query,tuple):
|
|||
print("--- Deleted %i rows from %s stats: %.3f seconds ---" % (allrows,label,end_time - start_time - minustime))
|
||||
|
||||
def delete_old_stats(mysql):
|
||||
threshold=(utcnow() - datetime.timedelta(days=CONFIG["router_stat_days"])).timestamp()
|
||||
threshold_netif=(utcnow() - datetime.timedelta(days=CONFIG["router_stat_netif"])).timestamp()
|
||||
threshold = (utcnow() - datetime.timedelta(days=CONFIG["router_stat_days"])).timestamp()
|
||||
threshold_netif = (utcnow() - datetime.timedelta(days=CONFIG["router_stat_netif"])).timestamp()
|
||||
threshold_gw = mysql.formatdt(utcnow() - datetime.timedelta(hours=CONFIG["gw_netif_threshold_hours"]))
|
||||
|
||||
start_time = time.time()
|
||||
rowsaffected = mysql.execute("""
|
||||
|
@ -488,6 +489,13 @@ def delete_old_stats(mysql):
|
|||
"""
|
||||
delete_stats_helper(mysql,"netif-stats",query,(threshold_netif,))
|
||||
|
||||
start_time = time.time()
|
||||
allrows = mysql.execute("DELETE FROM gw_netif WHERE last_contact < %s",(threshold_gw,))
|
||||
mysql.commit()
|
||||
writelog(CONFIG["debug_dir"] + "/deletetime.txt", "Deleted %i rows from gw_netif: %.3f seconds" % (allrows,time.time() - start_time))
|
||||
print("--- Deleted %i rows from gw_netif: %.3f seconds ---" % (allrows,time.time() - start_time))
|
||||
|
||||
time.sleep(10)
|
||||
start_time = time.time()
|
||||
allrows=0
|
||||
events = mysql.fetchall("""
|
||||
|
|
Loading…
Reference in New Issue