diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 1cdbe06d..2af36594 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -505,6 +505,14 @@ class Database: # Start of Hand Writing routines. Idea is to provide a mixture of routines to store Hand data # however the calling prog requires. Main aims: # - existing static routines from fpdb_simple just modified + + def lock_for_insert(self): + """Lock tables in MySQL to try to speed inserts up""" + try: + self.get_cursor().execute(self.sql.query['lockForInsert']) + except: + print "Error during fdb.lock_for_insert:", str(sys.exc_value) + #end def lock_for_insert def storeHands(self, backend, site_hand_no, gametype_id diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index b75a17dc..d6c289c1 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -1562,6 +1562,13 @@ class Sql: else: # assume postgres self.query['analyze'] = "vacuum analyze" + if db_server == 'mysql': + self.query['lockForInsert'] = """ + lock tables hands write, handsplayers write, handsactions write, players write, hudcache write + """ + else: # assume postgres + self.query['lockForInsert'] = "" + if __name__== "__main__": # just print the default queries and exit s = Sql(game = 'razz', type = 'ptracks') diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index dde0875c..b6a19415 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -84,7 +84,7 @@ class Importer: self.fdb.db.rollback() # make sure all locks are released self.NEWIMPORT = False - self.allow_hudcache_rebuild = True; + self.allow_hudcache_rebuild = False; #Set functions def setCallHud(self, value): @@ -199,7 +199,7 @@ class Importer: self.fdb.afterBulkImport() else: print "No need to rebuild indexes." - if self.settings['dropHudCache'] == 'drop': + if self.allow_hudcache_rebuild and self.settings['dropHudCache'] == 'drop': self.database.rebuild_hudcache() else: print "No need to rebuild hudcache." @@ -323,24 +323,6 @@ class Importer: filter_name = filter.replace("ToFpdb", "") -# Example code for using threads & queues: (maybe for obj and import_fpdb_file??) -#def worker(): -# while True: -# item = q.get() -# do_work(item) -# q.task_done() -# -#q = Queue() -#for i in range(num_worker_threads): -# t = Thread(target=worker) -# t.setDaemon(True) -# t.start() -# -#for item in source(): -# q.put(item) -# -#q.join() # block until all tasks are done - mod = __import__(filter) obj = getattr(mod, filter_name, None) if callable(obj): @@ -397,6 +379,9 @@ class Importer: self.pos_in_file[file] = inputFile.tell() inputFile.close() + # fix fdb and database cursors before using this: + #self.database.lock_for_insert() # ok when using one thread + try: # sometimes we seem to be getting an empty self.lines, in which case, we just want to return. firstline = self.lines[0] except: