From: Ant Zucaro Date: Thu, 23 Aug 2012 11:40:51 +0000 (-0400) Subject: Wait for precondition checks before beginning the DB transaction. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e7ce68e8bd31559caa328a6ffa600ee8f3c3284b;p=xonotic%2Fxonstat.git Wait for precondition checks before beginning the DB transaction. 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. --- diff --git a/xonstat/views/submission.py b/xonstat/views/submission.py index 78f02c9..0bbdf7e 100644 --- a/xonstat/views/submission.py +++ b/xonstat/views/submission.py @@ -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))