From e143d5e7d197480bc88d43c7e6108c288d94d8fa Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 22 Feb 2015 14:21:39 -0400 Subject: [PATCH] avoid closing db handle when reconnecting to do a write --- Database/Handle.hs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Database/Handle.hs b/Database/Handle.hs index 049007bc43..dc3363e482 100644 --- a/Database/Handle.hs +++ b/Database/Handle.hs @@ -75,26 +75,20 @@ data Job type TableName = String workerThread :: T.Text -> TableName -> MVar Job -> IO () -workerThread db tablename jobs = catchNonAsync loop showerr +workerThread db tablename jobs = catchNonAsync (run loop) showerr where showerr e = liftIO $ warningIO $ "sqlite worker thread crashed: " ++ show e loop = do - r <- run queryloop - case r of - QueryJob _ -> loop + job <- liftIO $ takeMVar jobs + case job of + QueryJob a -> a >> loop -- change is run in a separate database connection -- since sqlite only supports a single writer at a -- time, and it may crash the database connection - ChangeJob a -> a run >> loop + ChangeJob a -> liftIO (a run) >> loop CloseJob -> return () - - queryloop = do - job <- liftIO $ takeMVar jobs - case job of - QueryJob a -> a >> queryloop - _ -> return job -- like runSqlite, but calls settle on the raw sql Connection. run a = do