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.
This commit is contained in:
Scott R. Parish 2010-02-01 09:04:43 -06:00
parent 4c369f7a92
commit 9bc616ccf5

View file

@ -441,7 +441,6 @@ findOne :: Connection -> FullCollection -> Selector -> IO (Maybe BsonDoc)
findOne c col sel = do findOne c col sel = do
cur <- query c col [] 0 (-1) sel [] cur <- query c col [] 0 (-1) sel []
el <- nextDoc cur el <- nextDoc cur
finish cur
return el return el
-- | Perform a query and return the result as a lazy list. Be sure to -- | Perform a query and return the result as a lazy list. Be sure to
@ -629,14 +628,17 @@ finish :: Cursor -> IO ()
finish cur = do finish cur = do
let h = cHandle $ curCon cur let h = cHandle $ curCon cur
cid <- readIORef $ curID cur cid <- readIORef $ curID cur
let body = runPut $ do if cid == 0
putI32 0 then return ()
putI32 1 else do
putI64 cid let body = runPut $ do
(_reqID, msg) <- packMsg (curCon cur) OPKillCursors body putI32 0
L.hPut h msg putI32 1
writeIORef (curClosed cur) True putI64 cid
return () (_reqID, msg) <- packMsg (curCon cur) OPKillCursors body
L.hPut h msg
writeIORef (curClosed cur) True
return ()
-- | The field key to index on. -- | The field key to index on.
type Key = L8.ByteString type Key = L8.ByteString