This commit is contained in:
parent
465fe5a5b1
commit
d02f725d51
8 changed files with 149 additions and 128 deletions
|
|
@ -97,31 +97,16 @@ defmodule Mv.Membership.Import.HeaderMapper do
|
|||
}
|
||||
|
||||
# Build reverse map: normalized_variant -> canonical_field
|
||||
# Cached on first access for performance
|
||||
# Computed on each access - the map is small enough that recomputing is fast
|
||||
# This avoids Module.get_attribute issues while maintaining simplicity
|
||||
defp normalized_to_canonical do
|
||||
cached = Process.get({__MODULE__, :normalized_to_canonical})
|
||||
|
||||
if cached do
|
||||
cached
|
||||
else
|
||||
map = build_normalized_to_canonical_map()
|
||||
Process.put({__MODULE__, :normalized_to_canonical}, map)
|
||||
map
|
||||
end
|
||||
end
|
||||
|
||||
# Builds the normalized variant -> canonical field map
|
||||
defp build_normalized_to_canonical_map do
|
||||
@member_field_variants_raw
|
||||
|> Enum.flat_map(&map_variants_to_normalized/1)
|
||||
|> Map.new()
|
||||
end
|
||||
|
||||
# Maps a canonical field and its variants to normalized tuples
|
||||
defp map_variants_to_normalized({canonical, variants}) do
|
||||
Enum.map(variants, fn variant ->
|
||||
{normalize_header(variant), canonical}
|
||||
|> Enum.flat_map(fn {canonical, variants} ->
|
||||
Enum.map(variants, fn variant ->
|
||||
{normalize_header(variant), canonical}
|
||||
end)
|
||||
end)
|
||||
|> Map.new()
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -139,28 +124,21 @@ defmodule Mv.Membership.Import.HeaderMapper do
|
|||
iex> HeaderMapper.known_member_fields()
|
||||
#MapSet<["email", "firstname", "lastname", "street", "postalcode", "city"]>
|
||||
"""
|
||||
# Known member fields computed at compile-time for performance and determinism
|
||||
@known_member_fields @member_field_variants_raw
|
||||
|> Map.keys()
|
||||
|> Enum.map(fn canonical ->
|
||||
# Normalize the canonical field name (e.g., :first_name -> "firstname")
|
||||
canonical
|
||||
|> Atom.to_string()
|
||||
|> String.replace("_", "")
|
||||
|> String.downcase()
|
||||
end)
|
||||
|> MapSet.new()
|
||||
|
||||
@spec known_member_fields() :: MapSet.t(String.t())
|
||||
def known_member_fields do
|
||||
cached = Process.get({__MODULE__, :known_member_fields})
|
||||
|
||||
if cached do
|
||||
cached
|
||||
else
|
||||
fields =
|
||||
@member_field_variants_raw
|
||||
|> Map.keys()
|
||||
|> Enum.map(fn canonical ->
|
||||
# Normalize the canonical field name (e.g., :first_name -> "firstname")
|
||||
canonical
|
||||
|> Atom.to_string()
|
||||
|> String.replace("_", "")
|
||||
|> String.downcase()
|
||||
end)
|
||||
|> MapSet.new()
|
||||
|
||||
Process.put({__MODULE__, :known_member_fields}, fields)
|
||||
fields
|
||||
end
|
||||
@known_member_fields
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
|||
|
|
@ -310,10 +310,10 @@ defmodule Mv.Membership.Import.MemberCSV do
|
|||
|
||||
case process_row(row_map, line_number, custom_field_lookup, actor) do
|
||||
{:ok, _member} ->
|
||||
update_inserted(acc)
|
||||
update_inserted({acc_inserted, acc_failed, acc_errors, acc_error_count, acc_truncated?})
|
||||
|
||||
{:error, error} ->
|
||||
handle_row_error(acc, error, current_error_count, max_errors)
|
||||
handle_row_error({acc_inserted, acc_failed, acc_errors, acc_error_count, acc_truncated?}, error, current_error_count, max_errors)
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue