Skip to content

Commit ff46b8d

Browse files
committed
Optimize task list performance
1 parent 2010caa commit ff46b8d

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lib/code_corps_web/controllers/task_list_controller.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ defmodule CodeCorpsWeb.TaskListController do
2828
end
2929
end
3030

31-
@preloads [:tasks]
31+
@preloads [tasks: [:github_issue, :github_pull_request, :task_skills, :user, :user_task]]
3232

3333
def preload(data) do
3434
Repo.preload(data, @preloads)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
defmodule CodeCorpsWeb.TaskInListView do
2+
@moduledoc false
3+
use CodeCorpsWeb, :view
4+
use JaSerializer.PhoenixView
5+
6+
def type, do: "task"
7+
8+
attributes [
9+
:archived, :created_at, :number, :order, :status, :title
10+
]
11+
12+
has_one :github_issue, type: "github-issue", field: :github_issue_id
13+
has_one :github_pull_request, serializer: CodeCorpsWeb.GithubPullRequestView, identifiers: :always
14+
has_one :github_repo, type: "github-repo", field: :github_repo_id
15+
has_one :project, type: "project", field: :project_id
16+
has_one :task_list, type: "task-list", field: :task_list_id
17+
has_one :user, type: "user", field: :user_id
18+
has_one :user_task, serializer: CodeCorpsWeb.UserTaskView, include: true
19+
20+
has_many :task_skills, serializer: CodeCorpsWeb.TaskSkillView, include: true
21+
end

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.TaskView, identifiers: :always
10+
has_many :tasks, serializer: CodeCorpsWeb.TaskInListView, include: true
1111
end

0 commit comments

Comments
 (0)