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:
parent
990e226254
commit
38e6e15a26
|
@ -1752,7 +1752,7 @@ class Database:
|
||||||
return self.get_last_insert_id(c)
|
return self.get_last_insert_id(c)
|
||||||
# def storeHand
|
# 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)
|
#print "DEBUG: %s %s %s" %(hid, pids, pdata)
|
||||||
if printdata:
|
if printdata:
|
||||||
import pprint
|
import pprint
|
||||||
|
@ -1858,15 +1858,16 @@ class Database:
|
||||||
pdata[p]['street4Raises']
|
pdata[p]['street4Raises']
|
||||||
) )
|
) )
|
||||||
|
|
||||||
q = self.sql.query['store_hands_players']
|
if insert:
|
||||||
q = q.replace('%s', self.sql.query['placeholder'])
|
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
|
return inserts
|
||||||
#print "DEBUG: q: %s" % q
|
|
||||||
c = self.get_cursor()
|
|
||||||
c.executemany(q, 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)
|
#print "DEBUG: %s %s %s" %(hid, pids, adata)
|
||||||
|
|
||||||
# This can be used to generate test data. Currently unused
|
# This can be used to generate test data. Currently unused
|
||||||
|
@ -1891,11 +1892,14 @@ class Database:
|
||||||
adata[a]['allIn']
|
adata[a]['allIn']
|
||||||
) )
|
) )
|
||||||
|
|
||||||
q = self.sql.query['store_hands_actions']
|
if insert:
|
||||||
q = q.replace('%s', self.sql.query['placeholder'])
|
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()
|
return inserts
|
||||||
c.executemany(q, inserts)
|
|
||||||
|
|
||||||
def storeHudCache(self, gid, pids, starttime, pdata):
|
def storeHudCache(self, gid, pids, starttime, pdata):
|
||||||
"""Update cached statistics. If update fails because no record exists, do an insert."""
|
"""Update cached statistics. If update fails because no record exists, do an insert."""
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<FreePokerToolsConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FreePokerToolsConfig.xsd">
|
<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
|
<!-- These values determine what stats are displayed in the HUD
|
||||||
|
|
||||||
|
|
|
@ -247,7 +247,7 @@ dealt whether they were seen in a 'dealt to' line
|
||||||
db.commit()
|
db.commit()
|
||||||
#end def prepInsert
|
#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
|
""" Function to insert Hand into database
|
||||||
Should not commit, and do minimal selects. Callers may want to cache commits
|
Should not commit, and do minimal selects. Callers may want to cache commits
|
||||||
db: a connected Database object"""
|
db: a connected Database object"""
|
||||||
|
@ -273,16 +273,19 @@ db: a connected Database object"""
|
||||||
|
|
||||||
self.dbid_hands = db.storeHand(hh, printdata = printtest)
|
self.dbid_hands = db.storeHand(hh, printdata = printtest)
|
||||||
|
|
||||||
db.storeHandsPlayers(self.dbid_hands, self.dbid_pids, hp,
|
hp_inserts = db.storeHandsPlayers(self.dbid_hands, self.dbid_pids, hp,
|
||||||
printdata = printtest)
|
insert=insert_data, hp_bulk = hp_data, printdata = printtest)
|
||||||
|
|
||||||
if self.saveActions:
|
if self.saveActions:
|
||||||
db.storeHandsActions(self.dbid_hands, self.dbid_pids, self.stats.getHandsActions(),
|
ha_inserts = db.storeHandsActions(self.dbid_hands, self.dbid_pids, self.stats.getHandsActions(),
|
||||||
printdata = printtest)
|
insert=insert_data, ha_bulk = ha_data, printdata = printtest)
|
||||||
else:
|
else:
|
||||||
log.info(_("Hand.insert(): hid #: %s is a duplicate") % hh['siteHandNo'])
|
log.info(_("Hand.insert(): hid #: %s is a duplicate") % hh['siteHandNo'])
|
||||||
self.is_duplicate = True # i.e. don't update hudcache
|
self.is_duplicate = True # i.e. don't update hudcache
|
||||||
raise FpdbHandDuplicate(hh['siteHandNo'])
|
raise FpdbHandDuplicate(hh['siteHandNo'])
|
||||||
|
|
||||||
|
return hp_inserts, ha_inserts
|
||||||
|
|
||||||
def updateHudCache(self, db):
|
def updateHudCache(self, db):
|
||||||
db.storeHudCache(self.dbid_gt, self.dbid_pids, self.startTime, self.stats.getHandsPlayers())
|
db.storeHudCache(self.dbid_gt, self.dbid_pids, self.startTime, self.stats.getHandsPlayers())
|
||||||
|
|
||||||
|
|
|
@ -473,12 +473,19 @@ class Importer:
|
||||||
handlist = hhc.getProcessedHands()
|
handlist = hhc.getProcessedHands()
|
||||||
self.pos_in_file[file] = hhc.getLastCharacterRead()
|
self.pos_in_file[file] = hhc.getLastCharacterRead()
|
||||||
to_hud = []
|
to_hud = []
|
||||||
|
hp_bulk = []
|
||||||
|
ha_bulk = []
|
||||||
|
i = 0
|
||||||
|
|
||||||
for hand in handlist:
|
for hand in handlist:
|
||||||
if hand is not None:
|
if hand is not None:
|
||||||
hand.prepInsert(self.database)
|
hand.prepInsert(self.database)
|
||||||
try:
|
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:
|
except Exceptions.FpdbHandDuplicate:
|
||||||
duplicates += 1
|
duplicates += 1
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user