Luke Plant avatar Luke Plant committed 7cbd001

Only use one DB connection

Comments (0)

Files changed (3)


 -- | 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 =
     -- 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` ""


   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]


         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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.