Skip to content

Commit

Permalink
Merge pull request absinthe-graphql#1330 from absinthe-graphql/bryanj…
Browse files Browse the repository at this point in the history
…os/registry_fix

Avoid table scans on registry
  • Loading branch information
benwilson512 authored Jul 29, 2024
2 parents f4a930c + 824cc41 commit 5705d9a
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions lib/absinthe/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,22 @@ defmodule Absinthe.Subscription do

@doc false
def get(pubsub, key) do
pubsub
|> registry_name
|> Registry.lookup(key)
|> 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)
name = registry_name(pubsub)

{doc_id, doc}
name
|> Registry.lookup(key)
|> MapSet.new(fn {_pid, doc_id} -> doc_id end)
|> Enum.reduce([], fn doc_id, acc ->
case Registry.lookup(name, doc_id) do
[] ->
acc

[{_pid, doc} | _rest] ->
doc = Map.update!(doc, :initial_phases, &PipelineSerializer.unpack/1)
[{doc_id, doc} | acc]
end
end)
|> Map.new()
end

@doc false
Expand Down

0 comments on commit 5705d9a

Please sign in to comment.