Skip to content

Commit

Permalink
lazily load the internal schema to avoid race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetised authored and alco committed Oct 2, 2023
1 parent 040c01b commit 6b14f5b
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ defmodule Electric.Postgres.Extension.SchemaCache do
internal_schema: nil
}

{:ok, state, {:continue, :init}}
{:ok, state}
end

@impl GenServer
Expand Down Expand Up @@ -267,6 +267,7 @@ defmodule Electric.Postgres.Extension.SchemaCache do
end

def handle_call(:internal_schema, _from, state) do
state = load_internal_schema(state)
{:reply, state.internal_schema, state}
end

Expand Down Expand Up @@ -368,8 +369,12 @@ defmodule Electric.Postgres.Extension.SchemaCache do
{:noreply, state}
end

def handle_continue(:init, state) do
{:noreply, %{state | internal_schema: SchemaLoader.internal_schema(state.backend)}}
defp load_internal_schema(%{internal_schema: nil} = state) do
%{state | internal_schema: SchemaLoader.internal_schema(state.backend)}
end

defp load_internal_schema(state) do
state
end

defp current_schema(%{current: nil} = state) do
Expand Down

0 comments on commit 6b14f5b

Please sign in to comment.