Skip to content

Commit

Permalink
[PERFORMANCE] [MER-0000] Port dashboard optimization to v29 (#5430)
Browse files Browse the repository at this point in the history
* stashing

* singularize the impl, remove DB calls

* fix issues, update tests

* unit test

* simplify test

* add comments

* Auto format

* eliminate bad unit test

* allow dashboard details to be turned off

* Auto format

* auto format

* add logging

* format

---------

Co-authored-by: darrensiegel <[email protected]>
  • Loading branch information
darrensiegel and darrensiegel authored Feb 22, 2025
1 parent 607527a commit 3ce9abe
Show file tree
Hide file tree
Showing 11 changed files with 531 additions and 1,177 deletions.
11 changes: 11 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ world_universities_and_domains_json =

default_sha = if Mix.env() == :dev, do: "DEV BUILD", else: "UNKNOWN BUILD"

get_env_as_boolean = fn key, default ->
System.get_env(key, default)
|> String.downcase()
|> String.trim()
|> case do
"true" -> true
_ -> false
end
end

config :oli,
instructor_dashboard_details: get_env_as_boolean.("INSTRUCTOR_DASHBOARD_DETAILS", "true"),
depot_coordinator: Oli.Delivery.DistributedDepotCoordinator,
depot_warmer_days_lookback: System.get_env("DEPOT_WARMER_DAYS_LOOKBACK", "5"),
depot_warmer_max_number_of_entries: System.get_env("DEPOT_WARMER_MAX_NUMBER_OF_ENTRIES", "0"),
Expand Down
1 change: 1 addition & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ if config_env() == :prod do

# General OLI app config
config :oli,
instructor_dashboard_details: get_env_as_boolean.("INSTRUCTOR_DASHBOARD_DETAILS", "true"),
depot_warmer_days_lookback: System.get_env("DEPOT_WARMER_DAYS_LOOKBACK", "5"),
depot_warmer_max_number_of_entries: System.get_env("DEPOT_WARMER_MAX_NUMBER_OF_ENTRIES", "0"),
s3_media_bucket_name: s3_media_bucket_name,
Expand Down
41 changes: 38 additions & 3 deletions lib/oli/analytics/summary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,35 @@ defmodule Oli.Analytics.Summary do
|> Oli.Repo.insert()
end

@doc """
Retrieves the resource summaries for the activities present on a specified page in a
specified section. If `only_for_activity_ids` is provided, only the activities with the
specified IDs will be included in the result. If `only_for_activity_ids` is nil, all
activities on the page will be included in the result.
"""
def summarize_activities_for_page(section_id, page_id, only_for_activity_ids) do
activity_constraint =
case only_for_activity_ids do
nil -> true
_ -> dynamic([rs, _], rs.activity_id in ^only_for_activity_ids)
end

# The only way to query resource summary for all activities in a page is
# to go through the response summary and constrain by page_id
from(rs in ResponseSummary,
join: s in ResourceSummary,
on: rs.activity_id == s.resource_id and rs.section_id == s.section_id,
where:
rs.project_id == -1 and rs.publication_id == -1 and rs.section_id == ^section_id and
rs.page_id == ^page_id,
where: s.user_id != -1 and s.project_id == -1 and s.publication_id == -1,
where: ^activity_constraint,
distinct: [s.resource_id, s.user_id, s.part_id],
select: s
)
|> Repo.all()
end

@doc """
Counts the number of attempts made by a list of students for a given activity in a given section.
"""
Expand Down Expand Up @@ -444,7 +473,13 @@ defmodule Oli.Analytics.Summary do
section_id :: integer(),
activity_resource_ids :: [integer()]
) :: [map()]
def get_response_summary_for(page_resource_id, section_id, activity_resource_ids) do
def get_response_summary_for(page_resource_id, section_id, only_for_activity_ids \\ nil) do
activity_constraint =
case only_for_activity_ids do
nil -> true
_ -> dynamic([s, _], s.activity_id in ^only_for_activity_ids)
end

from(rs in ResponseSummary,
join: rpp in ResourcePartResponse,
on: rs.resource_part_response_id == rpp.id,
Expand All @@ -456,8 +491,8 @@ defmodule Oli.Analytics.Summary do
on: sr.user_id == u.id,
where:
rs.section_id == ^section_id and rs.page_id == ^page_resource_id and
rs.publication_id == -1 and rs.project_id == -1 and
rs.activity_id in ^activity_resource_ids,
rs.publication_id == -1 and rs.project_id == -1,
where: ^activity_constraint,
select: %{
part_id: rpp.part_id,
response: rpp.response,
Expand Down
Loading

0 comments on commit 3ce9abe

Please sign in to comment.