From 9bc616ccf597d8c72fac3c3e24696ff7ecc5d413 Mon Sep 17 00:00:00 2001 From: "Scott R. Parish" Date: Mon, 1 Feb 2010 09:04:43 -0600 Subject: [PATCH] finish: only close cursor if cursor-id is non-zero A '0' cursor-id means that no cursor was created, so there's nothing to kill. Also, findOne should never have a cursor opened for it, so no need to even call finish. --- Database/MongoDB.hs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Database/MongoDB.hs b/Database/MongoDB.hs index 0499791..e96607c 100644 --- a/Database/MongoDB.hs +++ b/Database/MongoDB.hs @@ -441,7 +441,6 @@ findOne :: Connection -> FullCollection -> Selector -> IO (Maybe BsonDoc) findOne c col sel = do cur <- query c col [] 0 (-1) sel [] el <- nextDoc cur - finish cur return el -- | Perform a query and return the result as a lazy list. Be sure to @@ -629,14 +628,17 @@ finish :: Cursor -> IO () finish cur = do let h = cHandle $ curCon cur cid <- readIORef $ curID cur - let body = runPut $ do - putI32 0 - putI32 1 - putI64 cid - (_reqID, msg) <- packMsg (curCon cur) OPKillCursors body - L.hPut h msg - writeIORef (curClosed cur) True - return () + if cid == 0 + then return () + else do + let body = runPut $ do + putI32 0 + putI32 1 + putI64 cid + (_reqID, msg) <- packMsg (curCon cur) OPKillCursors body + L.hPut h msg + writeIORef (curClosed cur) True + return () -- | The field key to index on. type Key = L8.ByteString