@@ -409,38 +409,48 @@ defmodule Arangox.Connection do
409
409
with (
410
410
{ nil , _cursors } <-
411
411
Map . pop ( cursors , cursor ) ,
412
- { :ok , _req , % Response { body: % { "hasMore" => has_more } } = response , state } <-
412
+ { :ok , _req , % Response { body: % { "hasMore" => true } } = response , state } <-
413
413
handle_execute (
414
414
query ,
415
415
% Request { method: :put , path: "/_api/cursor/" <> cursor } ,
416
416
opts ,
417
417
state
418
418
)
419
419
) do
420
- { cont_or_halt ( has_more ) , response , state }
420
+ { :cont , response , state }
421
421
else
422
- { % Response { body: % { "hasMore" => has_more } } = initial , cursors } ->
423
- { cont_or_halt ( has_more ) , initial , % { state | cursors: cursors } }
422
+ { % Response { body: % { "hasMore" => false } } = initial , cursors } ->
423
+ { :halt , initial , % { state | cursors: Map . put ( cursors , cursor , :noop ) } }
424
+
425
+ { % Response { body: % { "hasMore" => true } } = initial , cursors } ->
426
+ { :cont , initial , % { state | cursors: cursors } }
427
+
428
+ { :ok , _req , % Response { body: % { "hasMore" => false } } = response , state } ->
429
+ { :halt , response , % { state | cursors: Map . put ( cursors , cursor , :noop ) } }
424
430
425
431
error ->
426
432
error
427
433
end
428
434
end
429
435
430
- defp cont_or_halt ( true ) , do: :cont
431
- defp cont_or_halt ( false ) , do: :halt
432
-
433
436
@ impl true
434
437
def handle_deallocate ( query , cursor , opts , % __MODULE__ { cursors: cursors } = state ) do
435
438
state = % { state | cursors: Map . delete ( cursors , cursor ) }
436
- request = % Request { method: :delete , path: "/_api/cursor/" <> cursor }
437
439
438
- case handle_execute ( query , request , opts , state ) do
439
- { :ok , _req , response , state } ->
440
- { :ok , response , state }
440
+ case cursors do
441
+ % { ^ cursor => :noop } ->
442
+ { :ok , :noop , state }
441
443
442
- error ->
443
- error
444
+ _ ->
445
+ request = % Request { method: :delete , path: "/_api/cursor/" <> cursor }
446
+
447
+ case handle_execute ( query , request , opts , state ) do
448
+ { :ok , _req , response , state } ->
449
+ { :ok , response , state }
450
+
451
+ error ->
452
+ error
453
+ end
444
454
end
445
455
end
446
456
0 commit comments