use ecto fragment interpolation

pull/1916/head
saneery 6 years ago
parent 7680df0439
commit 8bbdb17265
  1. 45
      apps/explorer/lib/explorer/chain.ex
  2. 4
      apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex

@ -2853,34 +2853,47 @@ defmodule Explorer.Chain do
defp staking_pool_filter(query, :validator) do defp staking_pool_filter(query, :validator) do
where( where(
query, query,
[_], [address],
fragment(""" fragment(
(metadata->>'is_active')::boolean = true and """
(metadata->>'deleted')::boolean is not true and (?->>'is_active')::boolean = true and
(metadata->>'is_validator')::boolean = true (?->>'deleted')::boolean is not true and
""") (?->>'is_validator')::boolean = true
""",
address.metadata,
address.metadata,
address.metadata
)
) )
end end
defp staking_pool_filter(query, :active) do defp staking_pool_filter(query, :active) do
where( where(
query, query,
[_], [address],
fragment(""" fragment(
(metadata->>'is_active')::boolean = true and """
(metadata->>'deleted')::boolean is not true (?->>'is_active')::boolean = true and
""") (?->>'deleted')::boolean is not true
""",
address.metadata,
address.metadata
)
) )
end end
defp staking_pool_filter(query, :inactive) do defp staking_pool_filter(query, :inactive) do
where( where(
query, query,
[_], [address],
fragment(""" fragment(
(metadata->>'is_active')::boolean = false and """
(metadata->>'deleted')::boolean is not true (?->>'is_active')::boolean = false and
""") (?->>'deleted')::boolean is not true
""",
address.metadata,
address.metadata
)
) )
end end

@ -60,10 +60,10 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do
address_name in Address.Name, address_name in Address.Name,
where: where:
address_name.address_hash not in ^addresses and address_name.address_hash not in ^addresses and
fragment("(metadata->>'is_pool')::boolean = true"), fragment("(?->>'is_pool')::boolean = true", address_name.metadata),
update: [ update: [
set: [ set: [
metadata: fragment("metadata || '{\"deleted\": true}'::jsonb") metadata: fragment("? || '{\"deleted\": true}'::jsonb", address_name.metadata)
] ]
] ]
) )

Loading…
Cancel
Save