Skip to content

Commit

Permalink
[PERFORMANCE] [MER-3692] Improve "Manage Section" view loading (#5059)
Browse files Browse the repository at this point in the history
* use a simpler approach and query

* Auto format

---------

Co-authored-by: darrensiegel <[email protected]>
  • Loading branch information
darrensiegel and darrensiegel authored Aug 27, 2024
1 parent d017721 commit 7214126
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
31 changes: 15 additions & 16 deletions lib/oli/delivery/attempts/manual_grading.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ defmodule Oli.Delivery.Attempts.ManualGrading do
ActivityAttempt
}

def count_submitted_attempts(%Section{} = section) do
case browse_submitted_attempts(
section,
%Paging{limit: 1, offset: 0},
%Sorting{field: :date_submitted, direction: :asc},
%BrowseOptions{
user_id: nil,
activity_id: nil,
text_search: nil,
page_id: nil,
graded: nil
}
) do
[] -> 0
[item] -> item.total_count
end
def has_submitted_attempts(%Section{id: section_id}) do
query =
ActivityAttempt
|> join(:left, [aa], resource_attempt in ResourceAttempt,
on: aa.resource_attempt_id == resource_attempt.id
)
|> join(:left, [_, resource_attempt], ra in ResourceAccess,
on: resource_attempt.resource_access_id == ra.id
)
|> where(
[aa, _resource_attempt, resource_access],
resource_access.section_id == ^section_id and aa.lifecycle_state == :submitted
)

Repo.exists?(query)
end

@doc """
Expand Down
10 changes: 5 additions & 5 deletions lib/oli_web/live/sections/overview_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ defmodule OliWeb.Sections.OverviewView do
user: user,
section: section,
updates_count: updates_count,
submission_count:
Oli.Delivery.Attempts.ManualGrading.count_submitted_attempts(section),
has_submitted_attempts:
Oli.Delivery.Attempts.ManualGrading.has_submitted_attempts(section),
collab_space_config: collab_space_config,
resource_slug: revision_slug,
show_required_section_config: show_required_section_config,
Expand Down Expand Up @@ -114,7 +114,7 @@ defmodule OliWeb.Sections.OverviewView do
attr(:section, :any, default: nil)
attr(:instructors, :list, default: [])
attr(:updates_count, :integer)
attr(:submission_count, :integer)
attr(:has_submitted_attempts, :boolean)
attr(:section_has_student_data, :boolean)

def render(assigns) do
Expand Down Expand Up @@ -324,8 +324,8 @@ defmodule OliWeb.Sections.OverviewView do
class="btn btn-link"
>
Score Manually Graded Activities
<%= if @submission_count > 0 do %>
<span class="badge badge-primary"><%= @submission_count %></span>
<%= if @has_submitted_attempts do %>
<span class="badge badge-primary">*</span>
<% end %>
</a>
</li>
Expand Down

0 comments on commit 7214126

Please sign in to comment.