From 8bbdb17265b3b2cf7c88ddb5234161683f880cdb Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 13 May 2019 11:53:02 +0300 Subject: [PATCH] use ecto fragment interpolation --- apps/explorer/lib/explorer/chain.ex | 45 ++++++++++++------- .../chain/import/runner/staking_pools.ex | 4 +- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index b2964c85b0..33992a41d1 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.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 diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex index f0e62b7e89..c7736efad9 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex @@ -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) ] ] )