Skip to content

Commit

Permalink
Load task lists progressively
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Nov 6, 2017
1 parent 26ea258 commit 9c69e3a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
17 changes: 13 additions & 4 deletions lib/code_corps_web/controllers/project_skill_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ defmodule CodeCorpsWeb.ProjectSkillController do

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

@spec show(Conn.t, map) :: Conn.t
def show(%Conn{} = conn, %{"id" => id}) do
with %ProjectSkill{} = project_skill <- ProjectSkill |> Repo.get(id) do
with %ProjectSkill{} = project_skill <- ProjectSkill |> Repo.get(id) |> preload() do
conn |> render("show.json-api", data: project_skill)
end
end
Expand All @@ -26,8 +26,9 @@ defmodule CodeCorpsWeb.ProjectSkillController do
def create(%Conn{} = conn, %{} = params) do
with %User{} = current_user <- conn |> Guardian.Plug.current_resource,
{:ok, :authorized} <- current_user |> Policy.authorize(:create, %ProjectSkill{}, params),
{:ok, %ProjectSkill{} = project_skill} <- %ProjectSkill{} |> ProjectSkill.create_changeset(params) |> Repo.insert do

{:ok, %ProjectSkill{} = project_skill} <- %ProjectSkill{} |> ProjectSkill.create_changeset(params) |> Repo.insert(),
project_skill <- preload(project_skill)
do
current_user.id |> SegmentTracker.track("Added Project Skill", project_skill)
conn |> put_status(:created) |> render("show.json-api", data: project_skill)
end
Expand All @@ -44,4 +45,12 @@ defmodule CodeCorpsWeb.ProjectSkillController do
conn |> Conn.assign(:project_skill, project_skill) |> send_resp(:no_content, "")
end
end

@preloads [
:skill
]

def preload(data) do
Repo.preload(data, @preloads)
end
end
2 changes: 1 addition & 1 deletion lib/code_corps_web/controllers/task_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ defmodule CodeCorpsWeb.TaskController do
end
end

@preloads [:comments, :github_pull_request, :task_skills, :user_task]
@preloads [:comments, :github_pull_request, :task_skills, :user, [user_task: :user]]

def preload(data) do
timing("TaskController", "preload") do
Expand Down
9 changes: 5 additions & 4 deletions lib/code_corps_web/views/project_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ defmodule CodeCorpsWeb.ProjectView do
:total_monthly_donated, :updated_at, :website
]

has_one :organization, serializer: CodeCorpsWeb.OrganizationView, include: true
has_one :organization, type: "organization", field: :organization_id
has_one :stripe_connect_plan, serializer: CodeCorpsWeb.StripeConnectPlanView

has_many :donation_goals, serializer: CodeCorpsWeb.DonationGoalView, identifiers: :always
has_many :project_categories, serializer: CodeCorpsWeb.ProjectCategoryView, include: true
has_many :project_categories, serializer: CodeCorpsWeb.ProjectCategoryView, identifiers: :always
has_many :project_github_repos, serializer: CodeCorpsWeb.ProjectGithubRepoView, identifiers: :always
has_many :project_skills, serializer: CodeCorpsWeb.ProjectSkillView, include: true
has_many :project_users, serializer: CodeCorpsWeb.ProjectUserView, include: true
has_many :project_skills, serializer: CodeCorpsWeb.ProjectSkillView, identifiers: :always
has_many :project_users, serializer: CodeCorpsWeb.ProjectUserView, identifiers: :always
has_many :tasks, serializer: CodeCorpsWeb.TaskView, identifiers: :always
has_many :task_lists, serializer: CodeCorpsWeb.TaskListView, identifiers: :always

def can_activate_donations(project, _conn) do
Expand Down
2 changes: 1 addition & 1 deletion lib/code_corps_web/views/task_list_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ defmodule CodeCorpsWeb.TaskListView do

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

has_many :tasks, serializer: CodeCorpsWeb.TaskInListView, include: true
has_many :tasks, serializer: CodeCorpsWeb.TaskView, identifiers: :always
end

0 comments on commit 9c69e3a

Please sign in to comment.