Skip to content

Commit

Permalink
Add Scout tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Oct 28, 2017
1 parent 2a926dc commit 4984202
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
18 changes: 11 additions & 7 deletions lib/code_corps/task/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ defmodule CodeCorps.Task.Query do
Holds queries used to retrieve a list of, or a single `Task` record from the
database, using a provided map of parameters/filters.
"""

import Ecto.Query
import ScoutApm.Tracing

alias CodeCorps.{Helpers, Task, Repo}
alias Ecto.Queryable
Expand All @@ -18,13 +20,15 @@ defmodule CodeCorps.Task.Query do
"""
@spec list(map) :: list(Project.t)
def list(%{} = params) do
Task
|> Helpers.Query.id_filter(params)
|> apply_archived_status(params)
|> apply_status(params)
|> apply_optional_filters(params)
|> order_by([asc: :order])
|> Repo.all()
timing("Task.Query", "list") do
Task
|> Helpers.Query.id_filter(params)
|> apply_archived_status(params)
|> apply_status(params)
|> apply_optional_filters(params)
|> order_by([asc: :order])
|> Repo.all()
end
end

@spec apply_optional_filters(Queryable.t, map) :: Queryable.t
Expand Down
14 changes: 9 additions & 5 deletions lib/code_corps_web/controllers/task_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ defmodule CodeCorpsWeb.TaskController do

alias CodeCorps.{Analytics.SegmentTracker, Task, Policy, User}

import ScoutApm.Tracing

action_fallback CodeCorpsWeb.FallbackController
plug CodeCorpsWeb.Plug.DataToAttributes
plug CodeCorpsWeb.Plug.IdsToIntegers

@spec index(Conn.t, map) :: Conn.t
def index(%Conn{} = conn, %{} = params) do
with tasks <- Task.Query.list(params),
tasks <- preload(tasks)
do
tasks = Task.Query.list(params)
tasks = preload(tasks)
timing("JaSerializer", "render") do
conn |> render("index.json-api", data: tasks)
end
end
Expand All @@ -21,7 +23,7 @@ defmodule CodeCorpsWeb.TaskController do
def show(%Conn{} = conn, %{} = params) do
with %Task{} = task <- Task.Query.find(params),
task <- preload(task)
do
do
conn |> render("show.json-api", data: task)
end
end
Expand Down Expand Up @@ -63,7 +65,9 @@ defmodule CodeCorpsWeb.TaskController do
@preloads [:comments, :github_pull_request, :task_skills, :user_task]

def preload(data) do
Repo.preload(data, @preloads)
timing("TaskController", "preload") do
Repo.preload(data, @preloads)
end
end

# tracking
Expand Down

0 comments on commit 4984202

Please sign in to comment.