api/alfred: Suppress duplicate key errors for stats (workaround!)

Sometimes two queries want to insert the same entry into the
router stats table, although we check for that right before the
query is made. One can suppress this by using ON DUPLICATE KEY UPDATE
to ignore the second (redundant) entry.

This is no fix, but will work until this is examined more thoroughly.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler 2018-03-15 11:46:22 +01:00
parent ca41035654
commit c94da39798

View File

@ -563,6 +563,7 @@ def new_router_stats(mysql, router_id, uptime, router_update, netifdict, statsti
INSERT INTO router_stats (time, router, sys_memfree, sys_membuff, sys_memcache, loadavg, sys_procrun, sys_proctot,
clients, clients_eth, clients_w2, clients_w5, airtime_w2, airtime_w5)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
ON DUPLICATE KEY UPDATE time=time
""",(
time,
router_id,
@ -612,6 +613,7 @@ def new_router_stats(mysql, router_id, uptime, router_update, netifdict, statsti
mysql.executemany("""
INSERT INTO router_stats_netif (time, router, netif, rx, tx)
VALUES (%s, %s, %s, %s, %s)
ON DUPLICATE KEY UPDATE time=time
""",ndata)
# reuse timestamp from router_stats to avoid additional queries
@ -623,6 +625,7 @@ def new_router_stats(mysql, router_id, uptime, router_update, netifdict, statsti
mysql.executemany("""
INSERT INTO router_stats_neighbor (time, router, mac, quality)
VALUES (%s, %s, %s, %s)
ON DUPLICATE KEY UPDATE time=time
""",nbdata)
# reuse timestamp from router_stats to avoid additional queries
@ -634,6 +637,7 @@ def new_router_stats(mysql, router_id, uptime, router_update, netifdict, statsti
mysql.executemany("""
INSERT INTO router_stats_gw (time, router, mac, quality)
VALUES (%s, %s, %s, %s)
ON DUPLICATE KEY UPDATE time=time
""",gwdata)
def calculate_network_io(mysql, router_id, uptime, router_update):