summaryrefslogtreecommitdiff
path: root/Database
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-02-22 14:21:39 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-02-22 14:21:39 -0400
commit3fe6936c8b0882644655a5e4044c55798b8fbddb (patch)
treee00ad65e26afecdfe0d0b1b9151a6883923c6b5f /Database
parentd99f98187fc2cb79e879dcc5047fcf31fd934782 (diff)
avoid closing db handle when reconnecting to do a write
Diffstat (limited to 'Database')
-rw-r--r--Database/Handle.hs16
1 files changed, 5 insertions, 11 deletions
diff --git a/Database/Handle.hs b/Database/Handle.hs
index 049007bc4..dc3363e48 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