Skip to content

Commit

Permalink
don't need to double check if schema is tracked, we already know
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Nelson committed Dec 4, 2024
1 parent 18a1424 commit 618eb5b
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions lib/tracking/tracking.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,27 @@ defmodule ExAudit.Tracking do
def compare_versions(action, old, new) do
schema = Map.get(old, :__struct__, Map.get(new, :__struct__))

if schema in tracked_schemas() do
assocs = schema.__schema__(:associations)

patch =
ExAudit.Diff.diff(
ExAudit.Tracker.map_struct(old) |> Map.drop(assocs),
ExAudit.Tracker.map_struct(new) |> Map.drop(assocs)
)

case patch do
:not_changed ->
[]

patch ->
params = %{
entity_id: Map.get(old, :id) || Map.get(new, :id),
entity_schema: schema,
patch: patch,
action: action
}

[params]
end
else
[]
assocs = schema.__schema__(:associations)

patch =
ExAudit.Diff.diff(
ExAudit.Tracker.map_struct(old) |> Map.drop(assocs),
ExAudit.Tracker.map_struct(new) |> Map.drop(assocs)
)

case patch do
:not_changed ->
[]

patch ->
params = %{
entity_id: Map.get(old, :id) || Map.get(new, :id),
entity_schema: schema,
patch: patch,
action: action
}

[params]
end
end

Expand Down

0 comments on commit 618eb5b

Please sign in to comment.