Commits

Luke Plant committed 7cbd001

Only use one DB connection

Comments (0)

Files changed (3)

src/Blog/Forms.hs

 
 -- | extract the posted data from a POST request and build
 -- a Comment from it, returning a Comment and a list of validation errors
-validateComment creds postedData blogpost =
+validateComment cn creds postedData blogpost =
     do
     -- TODO - nicer mechanism for validation
 
     --    this will catch most humans using a browser
 
       ts <- getTimestamp
-      spamwords <- getSpamWords
+      spamwords <- getSpamWords cn
       let text = postedData "message" `captureOrDefault` ""
       let name = strip (postedData "name" `captureOrDefault` "")
       let email = postedData "email" `captureOrDefault` ""

src/Blog/Model.hs

                      )
   return ()
 
-getSpamWords :: IO [String]
-getSpamWords = do
+getSpamWords :: (IConnection conn) => conn -> IO [String]
+getSpamWords cn = do
   cn <- DB.connect
   res <- quickQuery' cn getSpamWordsQuery []
   return [fromSql $ row !! 0 | row <- res]

src/Blog/Views.hs

         case requestMethod req of
           "POST" -> do
             creds <- getCredentials req
-            (commentData, commentErrors, commentExtra) <- validateComment creds (getPOST req) post
+            (commentData, commentErrors, commentExtra) <- validateComment cn creds (getPOST req) post
             if null commentErrors
                then if isJust (getPOST req "submit")
                     then do