From 849ed1cb3792af468999a312449faf3e599e67c1 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Fri, 3 Jan 2014 01:00:01 +0200 Subject: deferred final commit for configurable backend addresses --- server.lua | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'server.lua') diff --git a/server.lua b/server.lua index 8d6cfee..0425b5e 100644 --- a/server.lua +++ b/server.lua @@ -1,5 +1,5 @@ --[[ -Copyright (c) 2012-2013 Kaarle Ritvanen +Copyright (c) 2012-2014 Kaarle Ritvanen See LICENSE file for license details --]] @@ -8,6 +8,7 @@ local mnode = acf.model.node local isinstance = acf.object.isinstance local json = require('cjson') +local posix = require('posix') local stringy = require('stringy') @@ -37,7 +38,11 @@ return function(env) else res = '' end return code, headers, coroutine.wrap( - function() coroutine.yield(res) end + function() + coroutine.yield(res) + posix.close(uwsgi.connection_fd()) + acf.commit() + end ) end @@ -77,7 +82,16 @@ return function(env) return wrap(400, nil, 'Invalid transaction ID') end end - local txn = acf.start_txn(parent_txn, true) + + local function new_txn(defer_validation) + return acf.start_txn{ + allow_commit_defer=true, + defer_validation=defer_validation, + parent=parent_txn + } + end + + local txn = new_txn(true) local function fetch_user(name) user = name and txn:fetch('/auth/users')[name] @@ -247,7 +261,7 @@ return function(env) session.last_txn_id = session.last_txn_id + 1 local txn_id = session.last_txn_id - session.txns[txn_id] = acf.start_txn(parent_txn) + session.txns[txn_id] = new_txn() return 204, {['X-ACF-Transaction-ID']=txn_id} end -- cgit v1.2.3