Skip to content

Commit

Permalink
Rework label query when slug is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanIvanoff committed Dec 18, 2023
1 parent e5f0345 commit ab942df
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions lib/sanbase/clickhouse/label/label.ex
Original file line number Diff line number Diff line change
Expand Up @@ -335,33 +335,24 @@ defmodule Sanbase.Clickhouse.Label do
WHERE
address IN [{{addresses}}] AND blockchain = {{blockchain}}
) AS a
#{maybe_join_slug(slug)}
LEFT JOIN
(
SELECT
label_id,
key,
value,
asset_name,
multiIf(
#{if slug, do: "asset_name != {{slug}} AND "} key = 'whale', NULL,
key
) AS filtered_key
FROM
label_metadata
) AS m USING (label_id)
WHERE m.filtered_key IS NOT NULL
GROUP BY address
)
)
"""
end

defp maybe_join_slug(nil), do: ""

defp maybe_join_slug(slug) when not is_nil(slug) do
# TODO: Describe what this does exactly
"""
LEFT JOIN
(
SELECT
label_id,
key,
value,
asset_name,
multiIf(
asset_name != {{slug}} AND key = 'whale', NULL,
key
) AS filtered_key
FROM
label_metadata
) AS m USING (label_id)
WHERE m.filtered_key IS NOT NULL
GROUP BY address
"""
end
end

0 comments on commit ab942df

Please sign in to comment.