Skip to content
Snippets Groups Projects
Unverified Commit 58b75e43 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

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).
parent e3436a5b
Branches
Tags
1 merge request!8Auth cache
......@@ -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()
......
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