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
where(
query,
[_],
fragment("""
(metadata->>'is_active')::boolean = true and
(metadata->>'deleted')::boolean is not true and
(metadata->>'is_validator')::boolean = true
""")
[address],
fragment(
"""
(?->>'is_active')::boolean = true and
(?->>'deleted')::boolean is not true and
(?->>'is_validator')::boolean = true
""",
address.metadata,
address.metadata,
address.metadata
)
)
end
defp staking_pool_filter(query, :active) do
where(
query,
[_],
fragment("""
(metadata->>'is_active')::boolean = true and
(metadata->>'deleted')::boolean is not true
""")
[address],
fragment(
"""
(?->>'is_active')::boolean = true and
(?->>'deleted')::boolean is not true
""",
address.metadata,
address.metadata
)
)
end
defp staking_pool_filter(query, :inactive) do
where(
query,
[_],
fragment("""
(metadata->>'is_active')::boolean = false and
(metadata->>'deleted')::boolean is not true
""")
[address],
fragment(
"""
(?->>'is_active')::boolean = false and
(?->>'deleted')::boolean is not true
""",
address.metadata,
address.metadata
)
)
end

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

Loading…
Cancel
Save