Skip to content

Commit 1e40355

Browse files
committed
noop cursor deallocation when already discarded by server
1 parent dfcd41b commit 1e40355

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

lib/arangox/connection.ex

+23-13
Original file line numberDiff line numberDiff line change
@@ -409,38 +409,48 @@ defmodule Arangox.Connection do
409409
with(
410410
{nil, _cursors} <-
411411
Map.pop(cursors, cursor),
412-
{:ok, _req, %Response{body: %{"hasMore" => has_more}} = response, state} <-
412+
{:ok, _req, %Response{body: %{"hasMore" => true}} = response, state} <-
413413
handle_execute(
414414
query,
415415
%Request{method: :put, path: "/_api/cursor/" <> cursor},
416416
opts,
417417
state
418418
)
419419
) do
420-
{cont_or_halt(has_more), response, state}
420+
{:cont, response, state}
421421
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)}}
424430

425431
error ->
426432
error
427433
end
428434
end
429435

430-
defp cont_or_halt(true), do: :cont
431-
defp cont_or_halt(false), do: :halt
432-
433436
@impl true
434437
def handle_deallocate(query, cursor, opts, %__MODULE__{cursors: cursors} = state) do
435438
state = %{state | cursors: Map.delete(cursors, cursor)}
436-
request = %Request{method: :delete, path: "/_api/cursor/" <> cursor}
437439

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}
441443

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
444454
end
445455
end
446456

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Arangox.MixProject do
22
use Mix.Project
33

4-
@version "0.4.2"
4+
@version "0.4.3"
55
@description """
66
ArangoDB 3.3.9+ driver for Elixir with connection pooling, VelocyStream, \
77
support for Active Failover, transactions and cursors.

0 commit comments

Comments
 (0)