Reuse existing addresses when creating an event

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-08-22 15:57:44 +02:00
parent ebf5534003
commit 0e0b68445b
22 changed files with 410 additions and 121 deletions

View File

@@ -20,6 +20,18 @@ defmodule MobilizonWeb.Resolvers.Address do
addresses = Task.await(local_addresses) ++ Task.await(remote_addresses)
# If we have results with same origin_id than those locally saved, don't return them
addresses =
Enum.reduce(addresses, %{}, fn address, addresses ->
if Map.has_key?(addresses, address.origin_id) && !is_nil(address.url) do
addresses
else
Map.put(addresses, address.origin_id, address)
end
end)
addresses = Map.values(addresses)
{:ok, addresses}
end