Modified import_file_dict() so that it stores HandsPlayers and HandsActions inserts in a temprorary list. Once the end of the handlist is reached, an executemany() bulk insert is done.

This commit is contained in:
chaz@pokeit.co 2011-01-01 15:40:06 -05:00
parent 990e226254
commit 38e6e15a26
4 changed files with 34 additions and 20 deletions

View File

@ -1752,7 +1752,7 @@ class Database:
return self.get_last_insert_id(c)
# def storeHand
def storeHandsPlayers(self, hid, pids, pdata, printdata = False):
def storeHandsPlayers(self, hid, pids, pdata, hp_bulk = None, insert = False, printdata = False):
#print "DEBUG: %s %s %s" %(hid, pids, pdata)
if printdata:
import pprint
@ -1858,15 +1858,16 @@ class Database:
pdata[p]['street4Raises']
) )
q = self.sql.query['store_hands_players']
q = q.replace('%s', self.sql.query['placeholder'])
if insert:
hp_bulk += inserts
q = self.sql.query['store_hands_players']
q = q.replace('%s', self.sql.query['placeholder'])
c = self.get_cursor()
c.executemany(q, hp_bulk)
#print "DEBUG: inserts: %s" %inserts
#print "DEBUG: q: %s" % q
c = self.get_cursor()
c.executemany(q, inserts)
return inserts
def storeHandsActions(self, hid, pids, adata, printdata = False):
def storeHandsActions(self, hid, pids, adata, ha_bulk = None, insert = False, printdata = False):
#print "DEBUG: %s %s %s" %(hid, pids, adata)
# This can be used to generate test data. Currently unused
@ -1891,11 +1892,14 @@ class Database:
adata[a]['allIn']
) )
q = self.sql.query['store_hands_actions']
q = q.replace('%s', self.sql.query['placeholder'])
if insert:
ha_bulk += inserts
q = self.sql.query['store_hands_actions']
q = q.replace('%s', self.sql.query['placeholder'])
c = self.get_cursor()
c.executemany(q, ha_bulk)
c = self.get_cursor()
c.executemany(q, inserts)
return inserts
def storeHudCache(self, gid, pids, starttime, pdata):
"""Update cached statistics. If update fails because no record exists, do an insert."""

View File

@ -2,7 +2,7 @@
<FreePokerToolsConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FreePokerToolsConfig.xsd">
<import callFpdbHud = "True" interval = "10" fastStoreHudCache="False" hhArchiveBase="~/.fpdb/HandHistories/" saveActions="True" cacheSessions="False" sessionTimeout="30"></import>
<import callFpdbHud = "True" interval = "10" fastStoreHudCache="False" hhArchiveBase="~/.fpdb/HandHistories/" saveActions="True" cacheSessions="True" sessionTimeout="30"></import>
<!-- These values determine what stats are displayed in the HUD

View File

@ -247,7 +247,7 @@ dealt whether they were seen in a 'dealt to' line
db.commit()
#end def prepInsert
def insert(self, db, printtest = False):
def insert(self, db, hp_data = None, ha_data = None, insert_data=False, printtest = False):
""" Function to insert Hand into database
Should not commit, and do minimal selects. Callers may want to cache commits
db: a connected Database object"""
@ -273,16 +273,19 @@ db: a connected Database object"""
self.dbid_hands = db.storeHand(hh, printdata = printtest)
db.storeHandsPlayers(self.dbid_hands, self.dbid_pids, hp,
printdata = printtest)
hp_inserts = db.storeHandsPlayers(self.dbid_hands, self.dbid_pids, hp,
insert=insert_data, hp_bulk = hp_data, printdata = printtest)
if self.saveActions:
db.storeHandsActions(self.dbid_hands, self.dbid_pids, self.stats.getHandsActions(),
printdata = printtest)
ha_inserts = db.storeHandsActions(self.dbid_hands, self.dbid_pids, self.stats.getHandsActions(),
insert=insert_data, ha_bulk = ha_data, printdata = printtest)
else:
log.info(_("Hand.insert(): hid #: %s is a duplicate") % hh['siteHandNo'])
self.is_duplicate = True # i.e. don't update hudcache
raise FpdbHandDuplicate(hh['siteHandNo'])
return hp_inserts, ha_inserts
def updateHudCache(self, db):
db.storeHudCache(self.dbid_gt, self.dbid_pids, self.startTime, self.stats.getHandsPlayers())

View File

@ -473,12 +473,19 @@ class Importer:
handlist = hhc.getProcessedHands()
self.pos_in_file[file] = hhc.getLastCharacterRead()
to_hud = []
hp_bulk = []
ha_bulk = []
i = 0
for hand in handlist:
if hand is not None:
hand.prepInsert(self.database)
try:
hand.insert(self.database, printtest = self.settings['testData'])
hp_inserts, ha_inserts = hand.insert(self.database, hp_data = hp_bulk,
ha_data = ha_bulk, insert_data = len(handlist)==i,
printtest = self.settings['testData'])
hp_bulk += hp_inserts
ha_bulk += ha_inserts
except Exceptions.FpdbHandDuplicate:
duplicates += 1
else: