]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Wait for precondition checks before beginning the DB transaction.
authorAnt Zucaro <azucaro@gmail.com>
Thu, 23 Aug 2012 11:40:51 +0000 (07:40 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Thu, 23 Aug 2012 11:40:51 +0000 (07:40 -0400)
SQLA's DBSession implicitly starts a PG transaction. When this
happens before the precondition checks (blank game, verified req, etc)
then an unneccesary transaction is started. Delay grabbing a new
DBSession until AFTER these checks are done prevents these useless
transactions from occurring. This means we should see little to
no ROLLBACK transactions in Munin once this is in place.

xonstat/views/submission.py

index 78f02c94512301948da85053458c4d563f1726a8..0bbdf7e81d9a181c73c4108d78b56e2caa84e318 100644 (file)
@@ -101,7 +101,6 @@ def has_minimum_real_players(settings, player_events):
 
     real_players = num_real_players(player_events)
 
-    #TODO: put this into a config setting in the ini file?
     if real_players < minimum_required_players:
         flg_has_min_real_players = False
 
@@ -539,8 +538,6 @@ def stats_submit(request):
     Entry handler for POST stats submissions.
     """
     try:
-        session = DBSession()
-
         log.debug("\n----- BEGIN REQUEST BODY -----\n" + request.body +
                 "----- END REQUEST BODY -----\n\n")
 
@@ -579,6 +576,12 @@ def stats_submit(request):
         except:
             revision = "unknown"
 
+        #----------------------------------------------------------------------
+        # This ends the "precondition" section of sanity checks. All
+        # functions not requiring a database connection go ABOVE HERE.
+        #----------------------------------------------------------------------
+        session = DBSession()
+
         server = get_or_create_server(session=session, hashkey=idfp, 
                 name=game_meta['S'], revision=revision,
                 ip_addr=get_remote_addr(request))