From 6781d97539d1b3e72cca060504a718bc6dbcb52a Mon Sep 17 00:00:00 2001 From: Worros Date: Mon, 3 Aug 2009 09:35:22 +0800 Subject: [PATCH 1/3] Remove debug message --- pyfpdb/Database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 9d835844..65701e8f 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -1005,7 +1005,7 @@ class Database: c.execute ("SELECT id FROM Players WHERE name=%s", (name,)) tmp=c.fetchall() #print "recognisePlayerIDs, names[i]:",names[i],"tmp:",tmp - print "DEBUG: cache misses: %s" %self.cachemiss + #print "DEBUG: cache misses: %s" %self.cachemiss return tmp[0][0] From 5e66e48b75bca9d12d27cd467f0c938c958e6729 Mon Sep 17 00:00:00 2001 From: Worros Date: Tue, 4 Aug 2009 18:22:29 +0800 Subject: [PATCH 2/3] Some comments and cleanup to the recent Player insert code --- pyfpdb/Database.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index c8d831a1..2ceb6988 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -184,6 +184,7 @@ class Database: self.pcache = None # PlayerId cache self.cachemiss = 0 # Delete me later - using to count player cache misses + self.cachehit = 0 # Delete me later - using to count player cache hits # config while trying out new hudcache mechanism self.use_date_in_hudcache = True @@ -976,21 +977,26 @@ class Database: for player in pnames: result[player] = self.pcache[player] + # NOTE: Using the LambdaDict does the same thing as: + #if player in self.pcache: + # #print "DEBUG: cachehit" + # pass + #else: + # self.pcache[player] = self.insertPlayer(player, siteid) + #result[player] = self.pcache[player] return result def insertPlayer(self, name, site_id): - self.cachemiss += 1 result = None c = self.get_cursor() c.execute ("SELECT id FROM Players WHERE name=%s", (name,)) tmp=c.fetchall() if (len(tmp)==0): #new player c.execute ("INSERT INTO Players (name, siteId) VALUES (%s, %s)", (name, site_id)) + #Get last id might be faster here. c.execute ("SELECT id FROM Players WHERE name=%s", (name,)) tmp=c.fetchall() - #print "recognisePlayerIDs, names[i]:",names[i],"tmp:",tmp - #print "DEBUG: cache misses: %s" %self.cachemiss return tmp[0][0] From 2c9982cfffad185661b10906714f704820e4e61d Mon Sep 17 00:00:00 2001 From: Worros Date: Tue, 4 Aug 2009 18:30:39 +0800 Subject: [PATCH 3/3] Make sure the db connection is encoded using utf8 This has an issue with my current code, but may cause other issues. Keeping to a 1 line change incase we need to revert at some point in future. --- pyfpdb/fpdb_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index a92625fd..e9c17bd9 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -64,7 +64,7 @@ class fpdb_db: if backend==fpdb_db.MYSQL_INNODB: import MySQLdb try: - self.db = MySQLdb.connect(host = host, user = user, passwd = password, db = database, use_unicode=True) + self.db = MySQLdb.connect(host = host, user = user, passwd = password, db = database, use_unicode=True, charset="utf8") except: raise fpdb_simple.FpdbError("MySQL connection failed") elif backend==fpdb_db.PGSQL: