     where(total_query, [p], p.created_at < ^date)
   end
 
-  def page_of_posts_by_user_query(remaining_query, per_page, options) do
+  def page_of_posts_by_user_query(remaining_query, %{per_page: per_page} = options) do
     remaining_query
     |> order_by([p], [desc: p.created_at])
     |> limit(^per_page)

  end

  @spec posts_page(options) :: PostsPage.t
  def posts_page(%{} = options) do
    per_page = parse_per_page(options[:per_page])
    before = parse_before(options[:before])

    total_query = total_posts_by_user_query(options)
    remaining_query = remaining_posts_by_user_query(total_query, before)

    measure_segment {:db, "Ecto.UserPostsQuery"} do
      posts_task = Task.async(__MODULE__, :page_of_posts_by_user_query, [remaining_query, per_page, options])
      total_count_task = Task.async(__MODULE__, :count_and_pages_calc, [total_query, per_page])
      remaining_count_task = Task.async(__MODULE__, :count_and_pages_calc, [remaining_query, per_page])


      before: last_post_date,
    }
  end

  defp parse_before(%DateTime{} = before), do: before
  defp parse_before(nil), do: nil
