From 58b75e43560ac163cc430ed3a61787c5765c3be4 Mon Sep 17 00:00:00 2001
From: Michal 'vorner' Vaner <michal.vaner@nic.cz>
Date: Thu, 28 Jan 2016 10:23:03 +0100
Subject: [PATCH] authenticator: Cleanup around DB usage

Don't rollback the database when we don't use transactions (they are
useless here, with single select being done to refresh again and again).

Also, don't recycle the cursor, clean it up (it is reportedly better for
the DB).
---
 src/master/authenticator/authenticator.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/master/authenticator/authenticator.py b/src/master/authenticator/authenticator.py
index 4fc7052a..71736f57 100755
--- a/src/master/authenticator/authenticator.py
+++ b/src/master/authenticator/authenticator.py
@@ -40,26 +40,23 @@ with open(sys.argv[1]) as f:
 	config_data.readfp(f, sys.argv[1])
 
 db = None
-cursor = None
 cred_cache = {}
 lock = Lock()
 
 def openDB():
 	global db
-	global cursor
 	db = psycopg2.connect(database=config_data.get('main', 'db'), user=config_data.get('main', 'dbuser'), password=config_data.get('main', 'dbpasswd'))
-	cursor = db.cursor()
 
 openDB()
 
 def renew():
 	print "Caching auth data"
+	cursor = db.cursor()
 	cursor.execute('SELECT name, passwd, mechanism, builtin_passwd, slot_id FROM clients')
 	lines = cursor.fetchall()
 	global cred_cache
 	# This should replace the whole dictionary atomically.
 	cred_cache = dict(map(lambda l: (l[0], l[1:]), lines))
-	db.rollback()
 	print "Caching done"
 
 renew()
-- 
GitLab