refine new date option on hudcache rebuild

This commit is contained in:
sqlcoder 2009-09-27 01:42:26 +01:00
parent b054a9c09a
commit c1711c4e2e
3 changed files with 33 additions and 2 deletions

View File

@ -1132,6 +1132,32 @@ class Database:
print err
#end def rebuild_hudcache
def get_hero_hudcache_start(self):
"""fetches earliest stylekey from hudcache for one of hero's player ids"""
try:
self.hero, self.hero_ids = {}, {'dummy':-53} # make sure at least one value is used in sql
for site in self.config.get_supported_sites():
result = self.get_site_id(site)
if result:
site_id = result[0][0]
self.hero[site_id] = self.config.supported_sites[site].screen_name
self.hero_ids[site_id] = self.get_player_id(self.config, site, self.hero[site_id])
q = self.sql.query['get_hero_hudcache_start'].replace("<playerid_list>", str(tuple(self.hero_ids.values())))
c = self.get_cursor()
c.execute(q)
tmp = c.fetchone()
if tmp == None:
return self.hero_hudstart_def
else:
return "20"+tmp[0][1:3] + "-" + tmp[0][3:5] + "-" + tmp[0][5:7]
except:
err = traceback.extract_tb(sys.exc_info()[2])[-1]
print "Error rebuilding hudcache:", str(sys.exc_value)
print err
#end def get_hero_hudcache_start
def analyzeDB(self):
"""Do whatever the DB can offer to update index/table statistics"""

View File

@ -2818,9 +2818,14 @@ class Sql:
,'d' || substr(strftime('%Y%m%d', h.handStart),3,7)
"""
self.query['get_hero_hudcache_start'] = """select min(hc.styleKey)
from HudCache hc
where hc.playerId in <playerid_list>
and hc.styleKey like 'd%'"""
if db_server == 'mysql':
self.query['analyze'] = """
analyze table Autorates, GameTypes, Hands, HandsPlayers, Hudcache, Players
analyze table Autorates, GameTypes, Hands, HandsPlayers, HudCache, Players
, Settings, Sites, Tourneys, TourneysPlayers, TourneyTypes
"""
else: # assume postgres

View File

@ -263,7 +263,7 @@ class fpdb:
hb = gtk.HBox(True, 1)
self.start_date = gtk.Entry(max=12)
self.start_date.set_text(self.db.hero_hudstart_def)
self.start_date.set_text( self.db.get_hero_hudcache_start() )
lbl = gtk.Label(" Hero's cache starts: ")
btn = gtk.Button()
btn.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON))