       left_join: u in assoc(h, :users),
       as: :users
   end
+
+  defp preloaded_with_stages(contest_query) do
+    from [contests: c] in contest_query,
+      join: h in assoc(c, :host),
+      as: :hosts,
+      join: cc in assoc(c, :contest_categories),
+      as: :contest_categories,
+      join: p in assoc(cc, :performances),
+      preload: [host: {h, [stages: ^stages_query()]}, contest_categories: {cc, :category}]
+  end
 end

  end

  def get_public_contest(id) do
    public_contests_query() |> Repo.get(id)
  end

  def get_public_contest!(id) do
    public_contests_query() |> Repo.get!(id)
  end

  @doc """

  """
  def list_public_contests(opts \\ []) do
    query =
      public_contests_query()
      |> preloaded_with_stages
      |> order_by([contests: c], desc: c.start_date, desc: c.end_date, desc: c.round)
      |> order_by([hosts: h, contest_categories: cc], [h.name, cc.inserted_at])

    query =
      if opts[:current_only] do
