commit 060060133efba6c8b6a3a19aabe25bdc7b555264 Author: hiro hiro@torproject.org Date: Thu May 23 21:00:58 2019 +0200
Update stats db operations --- gettor/utils/db.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/gettor/utils/db.py b/gettor/utils/db.py index 525287b..63bcf2a 100644 --- a/gettor/utils/db.py +++ b/gettor/utils/db.py @@ -88,12 +88,18 @@ class SQLite3(object): Update statistics to the database """ now_str = datetime.now().strftime("%Y%m%d") - query = "INSERT INTO stats(num_requests, platform, language, command, "\ - "service, date) VALUES (1, ?, ?, ?, ?, ?) ON CONFLICT(platform, "\ - "language, command, service, date) DO UPDATE SET num_requests=num_requests+1" + + # This query isn't the nicest until upsert isn't supported + + 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( - 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)
def get_links(self, platform, language, status):
tor-commits@lists.torproject.org