Hey guys. I’m new to Elixir.
I made a simple app with users and orders and the page takes 5s to load. I suspect it’s because
Here is request log:
[info] GET /orders
[debug] Processing with ReviewsWeb.OrderController.index/2
Parameters: %{}
Pipelines: [:browser, :protected]
[debug] QUERY OK source="orders" db=4.8ms idle=18.4ms
SELECT o0."id", o0."asin", o0."purchase_date", o0."review_deadline_date", o0."review_link", o0."owner_id", o0."reviewer_id", o0."status_id", o0."problem_id", o0."type_id", o0."inserted_at", o0."updated_at" FROM "orders" AS o0 []
[debug] QUERY OK source="users" db=6.1ms idle=23.5ms
SELECT u0."id", u0."password_hash", u0."email", u0."inserted_at", u0."updated_at", u0."id" FROM "users" AS u0 WHERE (u0."id" = $1) [1]
[info] Sent 200 in 19ms
[info] GET /orders
[debug] Processing with ReviewsWeb.OrderController.index/2
Parameters: %{}
Pipelines: [:browser, :protected]
[debug] QUERY OK source="orders" db=2.3ms idle=1587.6ms
SELECT o0."id", o0."asin", o0."purchase_date", o0."review_deadline_date", o0."review_link", o0."owner_id", o0."reviewer_id", o0."status_id", o0."problem_id", o0."type_id", o0."inserted_at", o0."updated_at" FROM "orders" AS o0 []
[debug] QUERY OK source="users" db=1.3ms idle=1590.2ms
SELECT u0."id", u0."password_hash", u0."email", u0."inserted_at", u0."updated_at", u0."id" FROM "users" AS u0 WHERE (u0."id" = $1) [1]
[info] Sent 200 in 10ms
And here is my controller and context code:
def index(conn, _params) do
orders = Orders.list_orders()
render(conn, "index.html", orders: orders)
end
def list_orders do
Repo.all(from o in Order, preload: [:owner, :reviewer])
end
Here is what my routes
:
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :skip_csrf_protection do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
pipeline :protected do
plug Pow.Plug.RequireAuthenticated, error_handler: Pow.Phoenix.PlugErrorHandler
end
scope "/" do
pipe_through :skip_csrf_protection
pow_assent_authorization_post_callback_routes()
end
scope "/" do
pipe_through :browser
pow_routes()
pow_assent_routes()
end
scope "/", ReviewsWeb do
pipe_through :browser
get "/", PageController, :index
end
scope "/", ReviewsWeb do
pipe_through [:browser, :protected]
resources "/orders", OrderController
end
# Other scopes may use custom stacks.
# scope "/api", ReviewsWeb do
# pipe_through :api
# end
# Enables LiveDashboard only for development
#
# If you want to use the LiveDashboard in production, you should put
# it behind authentication and allow only admins to access it.
# If your application does not have an admins-only section yet,
# you can use Plug.BasicAuth to set up some basic authentication
# as long as you are also using SSL (which you should anyway).
if Mix.env() in [:dev, :test] do
import Phoenix.LiveDashboard.Router
scope "/" do
pipe_through :browser
live_dashboard "/dashboard", metrics: ReviewsWeb.Telemetry
end
end
Versions:
PostgreSQL 11
Erlang 23
Elixir 1.10.3
Phoenix 1.5.3
Phoenix Ecto 4.1
Ecto SQL 3.4