[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [gettor/master] Revert "Update stats db operations"



commit caa003c1e723aa2d7afad44889d1e6c6bafc34ac
Author: hiro <hiro@xxxxxxxxxxxxxx>
Date:   Thu May 23 21:55:43 2019 +0200

    Revert "Update stats db operations"
    
    This reverts commit 060060133efba6c8b6a3a19aabe25bdc7b555264.
---
 gettor/utils/db.py | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/gettor/utils/db.py b/gettor/utils/db.py
index 63bcf2a..525287b 100644
--- a/gettor/utils/db.py
+++ b/gettor/utils/db.py
@@ -88,18 +88,12 @@ class SQLite3(object):
 		Update statistics to the database
 		"""
 		now_str = datetime.now().strftime("%Y%m%d")
-
-		# 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;"
+		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"
 
 		return self.dbpool.runQuery(
-			query, (platform, language, command, service, now_str, platform, language, command, service, now_str)
+			query, (platform, language, command, service, now_str)
 		).addCallback(self.query_callback).addErrback(self.query_errback)
 
 	def get_links(self, platform, language, status):

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits