Skip to content

Commit

Permalink
Merge pull request #1268 from martosaur/am/split_doc_registry
Browse files Browse the repository at this point in the history
Register subscription doc under doc_id key rather than field_key
  • Loading branch information
benwilson512 authored Aug 16, 2023
2 parents a0afbe1 + 7b1c16a commit 8a5c293
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions lib/absinthe/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,14 @@ defmodule Absinthe.Subscription do
def subscribe(pubsub, field_key, doc_id, doc) do
registry = pubsub |> registry_name

doc_value = {
doc_id,
%{
initial_phases: PipelineSerializer.pack(doc.initial_phases),
source: doc.source
}
doc_value = %{
initial_phases: PipelineSerializer.pack(doc.initial_phases),
source: doc.source
}

pdict_add_field(doc_id, field_key)
{:ok, _} = Registry.register(registry, field_key, doc_value)
{:ok, _} = Registry.register(registry, field_key, doc_id)
{:ok, _} = Registry.register(registry, doc_id, doc_value)
end

defp pdict_fields(doc_id) do
Expand All @@ -172,9 +170,11 @@ defmodule Absinthe.Subscription do
registry = pubsub |> registry_name

for field_key <- pdict_fields(doc_id) do
Registry.unregister_match(registry, field_key, {doc_id, :_})
Registry.unregister(registry, field_key)
end

Registry.unregister(registry, doc_id)

pdict_delete_fields(doc_id)
:ok
end
Expand All @@ -184,7 +184,17 @@ defmodule Absinthe.Subscription do
pubsub
|> registry_name
|> Registry.lookup(key)
|> Map.new(fn {_, {doc_id, doc}} ->
|> then(fn doc_ids ->
pubsub
|> registry_name
|> Registry.select(
# We compose a list of match specs that basically mean "lookup all keys
# in the doc_ids list"
for {_, doc_id} <- doc_ids,
do: {{:"$1", :_, :"$2"}, [{:==, :"$1", doc_id}], [{{:"$1", :"$2"}}]}
)
end)
|> Map.new(fn {doc_id, doc} ->
doc = Map.update!(doc, :initial_phases, &PipelineSerializer.unpack/1)

{doc_id, doc}
Expand Down

0 comments on commit 8a5c293

Please sign in to comment.