Commit 06006013 authored by Hiro's avatar Hiro 🏄
Browse files

Update stats db operations

parent 9723be42
...@@ -88,12 +88,18 @@ class SQLite3(object): ...@@ -88,12 +88,18 @@ class SQLite3(object):
Update statistics to the database Update statistics to the database
""" """
now_str = datetime.now().strftime("%Y%m%d") now_str = datetime.now().strftime("%Y%m%d")
query = "INSERT INTO stats(num_requests, platform, language, command, "\
"service, date) VALUES (1, ?, ?, ?, ?, ?) ON CONFLICT(platform, "\ # This query isn't the nicest until upsert isn't supported
"language, command, service, date) DO UPDATE SET num_requests=num_requests+1"
query = "BEGIN;"\
"INSERT OR IGNORE INTO stats(num_requests, platform, language, "\
"command, service, date) VALUES (0, ?, ?, ?, ?, ?); "\
"UPDATE stats SET num_requests = num_requests + 1 WHERE platform=? "\
"AND language=? AND command=? AND service=? AND date=?; "\
"COMMIT;"
return self.dbpool.runQuery( return self.dbpool.runQuery(
query, (platform, language, command, service, now_str) query, (platform, language, command, service, now_str, platform, language, command, service, now_str)
).addCallback(self.query_callback).addErrback(self.query_errback) ).addCallback(self.query_callback).addErrback(self.query_errback)
def get_links(self, platform, language, status): def get_links(self, platform, language, status):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment