Skip to content

Commit

Permalink
Refactor function names
Browse files Browse the repository at this point in the history
  • Loading branch information
dersmon committed Aug 5, 2024
1 parent 1d4cbaa commit a67b124
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions publication/lib/field_publication/publications/search.ex
Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,18 @@ defmodule FieldPublication.Publications.Search do
)
end

def get_label_usage() do
def get_system_wide_label_usage() do
Cachex.get(:document_cache, :system_wide_label_usage)
|> case do
{:ok, nil} ->
update_label_usage()
evaluate_system_wide_label_usage()

{:ok, info} ->
info
end
end

def update_label_usage() do
def evaluate_system_wide_label_usage() do
info =
Publications.get_current_published()
|> Enum.map(fn %Publication{} = pub ->
Expand Down Expand Up @@ -561,7 +561,7 @@ defmodule FieldPublication.Publications.Search do
}) do
field_labels =
groups
|> Enum.map(&extract_label_for_fields/1)
|> Enum.map(&extract_labels_for_fields/1)
|> List.flatten()
|> Enum.reduce(%{}, fn result, acc -> Map.merge(result, acc) end)

Expand All @@ -581,7 +581,7 @@ defmodule FieldPublication.Publications.Search do
}
end

defp extract_label_for_fields(%{"fields" => fields}) do
defp extract_labels_for_fields(%{"fields" => fields}) do
fields
|> Stream.filter(fn %{"inputType" => input_type} ->
input_type != "relation"
Expand Down Expand Up @@ -885,7 +885,7 @@ defmodule FieldPublication.Publications.Search do
|> Enum.to_list()

switch_active_alias(publication)
update_label_usage()
evaluate_system_wide_label_usage()
end

defp flatten_input_types(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ defmodule FieldPublicationWeb.Presentation.SearchLive do
defp get_filter_label(opensearch_field_name) do
data_field_name = String.replace_suffix(opensearch_field_name, "_keyword", "")

label_info = Search.get_label_usage()
label_info = Search.get_system_wide_label_usage()

case label_info[:field_labels][data_field_name]["labels"] do
nil ->
Expand All @@ -212,7 +212,7 @@ defmodule FieldPublicationWeb.Presentation.SearchLive do
end

defp get_filter_value_label("category", opensearch_field_value) do
label_info = Search.get_label_usage()
label_info = Search.get_system_wide_label_usage()

case label_info[:category_labels][opensearch_field_value] do
nil ->
Expand All @@ -238,7 +238,7 @@ defmodule FieldPublicationWeb.Presentation.SearchLive do
end

defp get_filter_value_label(opensearch_field_name, opensearch_field_value) do
label_info = Search.get_label_usage()
label_info = Search.get_system_wide_label_usage()
data_field_name = String.replace_suffix(opensearch_field_name, "_keyword", "")

case label_info[:field_labels][data_field_name]["value_labels"] do
Expand Down

0 comments on commit a67b124

Please sign in to comment.