From 5cbbe12b655168ee2b7ca1c2bcb15b33d35a45fc Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Thu, 6 Nov 2014 11:02:19 -0800 Subject: [PATCH] Use transactions for only patch and put --- src/Middleware.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Middleware.hs b/src/Middleware.hs index c27443bf7..55b04f836 100644 --- a/src/Middleware.hs +++ b/src/Middleware.hs @@ -34,22 +34,22 @@ withDBConnection :: Pool Connection -> (Connection -> Application) -> Applicatio withDBConnection pool app req respond = withResource pool (\c -> app c req respond) +safeAction :: Request -> Bool +safeAction = (`notElem` ["PATCH", "PUT"]) . requestMethod + inTransaction :: Environment -> (Connection -> Application) -> Connection -> Application inTransaction env app conn req respond = - if env == Production && readOnlyRequest req + if env == Production && safeAction req then app conn req respond else finally (runRaw conn "begin" >> app conn req respond) (runRaw conn "commit") -readOnlyRequest :: Request -> Bool -readOnlyRequest req = requestMethod req `elem` ["GET", "HEAD", "OPTIONS"] - withSavepoint :: Environment -> (Connection -> Application) -> Connection -> Application withSavepoint env app conn req respond = - if env == Production && readOnlyRequest req + if env == Production && safeAction req then app conn req respond else do runRaw conn "savepoint req_sp"