|
|
@ -247,6 +247,7 @@ defmodule Explorer.Chain.OrderedCache do |
|
|
|
ConCache.update(cache_name(), ids_list_key(), fn ids -> |
|
|
|
ConCache.update(cache_name(), ids_list_key(), fn ids -> |
|
|
|
updated_list = |
|
|
|
updated_list = |
|
|
|
elements |
|
|
|
elements |
|
|
|
|
|
|
|
|> do_preloads() |
|
|
|
|> Enum.map(&{element_to_id(&1), &1}) |
|
|
|
|> Enum.map(&{element_to_id(&1), &1}) |
|
|
|
|> Enum.sort(&prevails?(&1, &2)) |
|
|
|
|> Enum.sort(&prevails?(&1, &2)) |
|
|
|
|> merge_and_update(ids || [], max_size()) |
|
|
|
|> merge_and_update(ids || [], max_size()) |
|
|
@ -258,6 +259,14 @@ defmodule Explorer.Chain.OrderedCache do |
|
|
|
|
|
|
|
|
|
|
|
def update(element), do: update([element]) |
|
|
|
def update(element), do: update([element]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp do_preloads(elements) do |
|
|
|
|
|
|
|
if Enum.empty?(preloads()) do |
|
|
|
|
|
|
|
elements |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
Explorer.Repo.preload(elements, preloads()) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp merge_and_update(_candidates, existing, 0) do |
|
|
|
defp merge_and_update(_candidates, existing, 0) do |
|
|
|
# if there is no more space in the list remove the remaining existing |
|
|
|
# if there is no more space in the list remove the remaining existing |
|
|
|
# elements and return an empty list |
|
|
|
# elements and return an empty list |
|
|
@ -323,17 +332,10 @@ defmodule Explorer.Chain.OrderedCache do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp put_element(element_id, element) do |
|
|
|
defp put_element(element_id, element) do |
|
|
|
full_element = |
|
|
|
|
|
|
|
if Enum.empty?(preloads()) do |
|
|
|
|
|
|
|
element |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
Explorer.Repo.preload(element, preloads()) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# dirty puts are a little faster than puts with locks. |
|
|
|
# dirty puts are a little faster than puts with locks. |
|
|
|
# this is not a problem because this is the only function modifying rows |
|
|
|
# this is not a problem because this is the only function modifying rows |
|
|
|
# and it only gets called inside `update`, which works isolated |
|
|
|
# and it only gets called inside `update`, which works isolated |
|
|
|
ConCache.dirty_put(cache_name(), element_id, full_element) |
|
|
|
ConCache.dirty_put(cache_name(), element_id, element) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
### Supervisor's child specification |
|
|
|
### Supervisor's child specification |
|
|
|