Skip to content

Commit 9c69e3a

Browse files
committed
Load task lists progressively
1 parent 26ea258 commit 9c69e3a

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

lib/code_corps_web/controllers/project_skill_controller.ex

+13-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ defmodule CodeCorpsWeb.ProjectSkillController do
1010

1111
@spec index(Conn.t, map) :: Conn.t
1212
def index(%Conn{} = conn, %{} = params) do
13-
with project_skills <- ProjectSkill |> Query.id_filter(params) |> Repo.all do
13+
with project_skills <- ProjectSkill |> Query.id_filter(params) |> Repo.all |> preload() do
1414
conn |> render("index.json-api", data: project_skills)
1515
end
1616
end
1717

1818
@spec show(Conn.t, map) :: Conn.t
1919
def show(%Conn{} = conn, %{"id" => id}) do
20-
with %ProjectSkill{} = project_skill <- ProjectSkill |> Repo.get(id) do
20+
with %ProjectSkill{} = project_skill <- ProjectSkill |> Repo.get(id) |> preload() do
2121
conn |> render("show.json-api", data: project_skill)
2222
end
2323
end
@@ -26,8 +26,9 @@ defmodule CodeCorpsWeb.ProjectSkillController do
2626
def create(%Conn{} = conn, %{} = params) do
2727
with %User{} = current_user <- conn |> Guardian.Plug.current_resource,
2828
{:ok, :authorized} <- current_user |> Policy.authorize(:create, %ProjectSkill{}, params),
29-
{:ok, %ProjectSkill{} = project_skill} <- %ProjectSkill{} |> ProjectSkill.create_changeset(params) |> Repo.insert do
30-
29+
{:ok, %ProjectSkill{} = project_skill} <- %ProjectSkill{} |> ProjectSkill.create_changeset(params) |> Repo.insert(),
30+
project_skill <- preload(project_skill)
31+
do
3132
current_user.id |> SegmentTracker.track("Added Project Skill", project_skill)
3233
conn |> put_status(:created) |> render("show.json-api", data: project_skill)
3334
end
@@ -44,4 +45,12 @@ defmodule CodeCorpsWeb.ProjectSkillController do
4445
conn |> Conn.assign(:project_skill, project_skill) |> send_resp(:no_content, "")
4546
end
4647
end
48+
49+
@preloads [
50+
:skill
51+
]
52+
53+
def preload(data) do
54+
Repo.preload(data, @preloads)
55+
end
4756
end

lib/code_corps_web/controllers/task_controller.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ defmodule CodeCorpsWeb.TaskController do
6262
end
6363
end
6464

65-
@preloads [:comments, :github_pull_request, :task_skills, :user_task]
65+
@preloads [:comments, :github_pull_request, :task_skills, :user, [user_task: :user]]
6666

6767
def preload(data) do
6868
timing("TaskController", "preload") do

lib/code_corps_web/views/project_view.ex

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ defmodule CodeCorpsWeb.ProjectView do
1414
:total_monthly_donated, :updated_at, :website
1515
]
1616

17-
has_one :organization, serializer: CodeCorpsWeb.OrganizationView, include: true
17+
has_one :organization, type: "organization", field: :organization_id
1818
has_one :stripe_connect_plan, serializer: CodeCorpsWeb.StripeConnectPlanView
1919

2020
has_many :donation_goals, serializer: CodeCorpsWeb.DonationGoalView, identifiers: :always
21-
has_many :project_categories, serializer: CodeCorpsWeb.ProjectCategoryView, include: true
21+
has_many :project_categories, serializer: CodeCorpsWeb.ProjectCategoryView, identifiers: :always
2222
has_many :project_github_repos, serializer: CodeCorpsWeb.ProjectGithubRepoView, identifiers: :always
23-
has_many :project_skills, serializer: CodeCorpsWeb.ProjectSkillView, include: true
24-
has_many :project_users, serializer: CodeCorpsWeb.ProjectUserView, include: true
23+
has_many :project_skills, serializer: CodeCorpsWeb.ProjectSkillView, identifiers: :always
24+
has_many :project_users, serializer: CodeCorpsWeb.ProjectUserView, identifiers: :always
25+
has_many :tasks, serializer: CodeCorpsWeb.TaskView, identifiers: :always
2526
has_many :task_lists, serializer: CodeCorpsWeb.TaskListView, identifiers: :always
2627

2728
def can_activate_donations(project, _conn) do

lib/code_corps_web/views/task_list_view.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ defmodule CodeCorpsWeb.TaskListView do
77

88
has_one :project, type: "project", field: :project_id
99

10-
has_many :tasks, serializer: CodeCorpsWeb.TaskInListView, include: true
10+
has_many :tasks, serializer: CodeCorpsWeb.TaskView, identifiers: :always
1111
end

0 commit comments

Comments
 (0)