diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 3c8b4246..354081f5 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -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("", 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""" diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index d4350ad5..abef4b76 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -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 + 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 diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 05121474..4703d96d 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -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))