mark pools as deleted if they don't exist in the list

pull/1916/head
saneery 6 years ago
parent 81956d27f2
commit 3c4d63149c
  1. 29
      apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex
  2. 1
      apps/indexer/lib/indexer/fetcher/staking_pools.ex

@ -41,6 +41,9 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do
|> Map.put(:timestamps, timestamps) |> Map.put(:timestamps, timestamps)
multi multi
|> Multi.run(:mark_as_deleted, fn repo, _ ->
mark_as_deleted(repo, changes_list, insert_options)
end)
|> Multi.run(:insert_staking_pools, fn repo, _ -> |> Multi.run(:insert_staking_pools, fn repo, _ ->
insert(repo, changes_list, insert_options) insert(repo, changes_list, insert_options)
end) end)
@ -49,6 +52,32 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do
@impl Import.Runner @impl Import.Runner
def timeout, do: @timeout def timeout, do: @timeout
defp mark_as_deleted(repo, changes_list, %{timeout: timeout}) when is_list(changes_list) do
addresses = Enum.map(changes_list, & &1.address_hash)
query =
from(
address_name in Address.Name,
where:
address_name.address_hash not in ^addresses and
fragment("(metadata->>'is_pool')::boolean = true"),
update: [
set: [
metadata: fragment("metadata || '{\"deleted\": true}'::jsonb")
]
]
)
try do
{_, result} = repo.update_all(query, [], timeout: timeout)
{:ok, result}
rescue
postgrex_error in Postgrex.Error ->
{:error, %{exception: postgrex_error}}
end
end
@spec insert(Repo.t(), [map()], %{ @spec insert(Repo.t(), [map()], %{
optional(:on_conflict) => Import.Runner.on_conflict(), optional(:on_conflict) => Import.Runner.on_conflict(),
required(:timeout) => timeout, required(:timeout) => timeout,

@ -125,6 +125,7 @@ defmodule Indexer.Fetcher.StakingPools do
pool pool
|> Map.delete(:staking_address) |> Map.delete(:staking_address)
|> Map.put(:mining_address, mining_address) |> Map.put(:mining_address, mining_address)
|> Map.put(:is_pool, true)
%{ %{
name: "anonymous", name: "anonymous",

Loading…
Cancel
Save