Skip to content

Commit

Permalink
Preload channels from survey.respondent_groups
Browse files Browse the repository at this point in the history
  • Loading branch information
anaPerezGhiglia committed Jul 30, 2024
1 parent 81a22d5 commit 15dd6fd
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions lib/ask_web/controllers/respondent_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1191,18 +1191,11 @@ defmodule AskWeb.RespondentController do
end

defp survey_log_entry_channel_names(survey) do
from(c in Ask.Channel,
select: {c.id, c.name},
where:
c.id in subquery(
from(e in SurveyLogEntry,
distinct: true,
select: e.channel_id,
where: e.survey_id == ^survey.id
)
)
)
|> Repo.all()
respondent_groups = Repo.preload(survey, :respondent_groups).respondent_groups
respondent_groups
|> Enum.flat_map(fn resp_group -> Repo.preload(resp_group, :channels).channels end )
|> Enum.map( fn channel -> {channel.id, channel.name} end)
|> MapSet.new # convert to set to remove duplicates
|> Enum.into(%{})
end

Expand Down

0 comments on commit 15dd6fd

Please sign in to comment.