Skip to content

Commit

Permalink
Do not cache sync beam code paths
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Jun 5, 2024
1 parent f522883 commit 35685ed
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lib/flame/code_sync.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule FLAME.CodeSync.PackagedStream do
tmp_dir: nil,
apps_to_start: [],
changed_paths: [],
sync_beam_hashes: %{},
deleted_paths: [],
purge_modules: [],
verbose: false
Expand All @@ -19,7 +20,7 @@ defmodule FLAME.CodeSync do
alias FLAME.CodeSync.PackagedStream

defstruct id: nil,
sync_beam_hashes: {},
sync_beam_hashes: %{},
copy_paths: nil,
sync_beams: nil,
extract_dir: nil,
Expand Down Expand Up @@ -169,6 +170,7 @@ defmodule FLAME.CodeSync do
id: code.id,
tmp_dir: code.tmp_dir,
extract_dir: code.extract_dir,
sync_beam_hashes: code.sync_beam_hashes,
changed_paths: code.changed_paths,
deleted_paths: code.deleted_paths,
purge_modules: code.purge_modules,
Expand Down Expand Up @@ -261,27 +263,31 @@ defmodule FLAME.CodeSync do

defp add_code_paths_from_tar(%PackagedStream{} = pkg, extract_dir) do
pkg.changed_paths
|> Enum.reduce({_consolidated = [], _regular = []}, fn rel_path, {cons, reg} ->
|> Enum.reduce({_consolidated = [], _regular = [], _beams = []}, fn rel_path,
{cons, reg, beams} ->
dir = extract_dir |> Path.join(rel_path) |> Path.dirname()

# todo filter only ebins

# purge consolidated protocols
with "consolidated" <- Path.basename(dir),
[mod_str, ""] <- rel_path |> Path.basename() |> String.split(".beam") do
mod = Module.concat([mod_str])
if pkg.verbose, do: log_verbose("purging consolidated protocol #{inspect(mod)}")
:code.purge(mod)
:code.delete(mod)
{[dir | cons], reg}
{[dir | cons], reg, beams}
else
_ -> {cons, [dir | reg]}
_ ->
case pkg.sync_beam_hashes do
%{^rel_path => _} -> {cons, reg, [dir | beams]}
%{} -> {cons, [dir | reg], beams}
end
end
end)
|> then(fn {cons, reg} ->
|> then(fn {cons, reg, beams} ->
# consolidated already in reverse order, which is what we want for prepend
consolidated = Enum.uniq(cons)
regular = reg |> Enum.uniq() |> Enum.reverse()
regular = Enum.uniq(reg)
sync_beams = Enum.uniq(beams)

if pkg.verbose do
if !Enum.empty?(consolidated),
Expand All @@ -291,8 +297,10 @@ defmodule FLAME.CodeSync do
do: log_verbose("appending code paths: #{inspect(regular)}")
end

Code.prepend_paths(consolidated, cache: true)
Code.prepend_paths(regular, cache: true)
Code.prepend_paths(consolidated, cache: true)
# don't cache for sync_beams
Code.prepend_paths(sync_beams)
:ok
end)
end
Expand Down

0 comments on commit 35685ed

Please sign in to comment.