From 41a9e422d5d107c75d7c8a9dc3ab077d113aae0e Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 29 Sep 2022 13:19:09 +0530 Subject: [PATCH] fix: course list page performance --- lms/hooks.py | 3 +- lms/lms/utils.py | 6 + lms/lms/widgets/CourseCard.html | 213 ++++++++++++++++---------------- 3 files changed, 115 insertions(+), 107 deletions(-) diff --git a/lms/hooks.py b/lms/hooks.py index 627cf2df..1e7176e8 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -198,7 +198,8 @@ jinja = { "lms.lms.utils.has_course_instructor_role", "lms.lms.utils.has_course_moderator_role", "lms.lms.utils.get_certificates", - "lms.lms.utils.format_number" + "lms.lms.utils.format_number", + "lms.lms.utils.get_lesson_count" ], "filters": [] } diff --git a/lms/lms/utils.py b/lms/lms/utils.py index 02452a69..b644fcae 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -508,4 +508,10 @@ def create_notification_log(doc, method): make_notification_logs(notification, users) +def get_lesson_count(course): + lesson_count = 0 + chapters = frappe.get_all("Chapter Reference", {"parent": course}, ["chapter"]) + for chapter in chapters: + lesson_count += frappe.db.count("Lesson Reference", {"parent": chapter.chapter}) + return lesson_count diff --git a/lms/lms/widgets/CourseCard.html b/lms/lms/widgets/CourseCard.html index 11af8e13..770247d5 100644 --- a/lms/lms/widgets/CourseCard.html +++ b/lms/lms/widgets/CourseCard.html @@ -14,116 +14,117 @@ {% endif %} -
-
- {% if get_lessons(course.name) | length %} -
- - - - {{ get_lessons(course.name) | length }} -
- {% endif %} - - {% if course.status and course.status != "Approved" %} - {% set pill_color = "gray" if course.status == "In Progress" else "orange" %} -
{{ course.status }}
- {% endif %} - - {% set student_count = get_students(course.name) | length %} - {% set avg_rating = get_average_rating(course.name) %} - {% if student_count %} +
+
+ {% set lesson_count = get_lesson_count(course.name) %} + {% if lesson_count %}
- - + + - {{ student_count }} + {{ lesson_count }}
- {% endif %} - - {% if avg_rating %} -
- - - - {{ frappe.utils.flt(avg_rating, frappe.get_system_settings("float_precision") or 3) }} -
- {% endif %} - - {% if course.paid_certificate %} -
- - - - - {{ format_amount(course.price_certificate, course.currency) }} - -
- {% endif %} -
-
{{ course.title }}
- - {% if membership and not read_only %} -
-
- {{ progress }} {{ _("Complete") }} -
-
-
{{ progress }}% {{ _("Completed") }}
- {% endif %} - - +
{{ course.title }}
+ + {% if membership and not read_only %} +
+
+ {{ progress }} {{ _("Complete") }} +
+
+
{{ progress }}% {{ _("Completed") }}
+ {% endif %} + +
+ + {% if read_only %} + + {% else %} + + {% set lesson_index = get_lesson_index(membership.current_lesson) if membership and + membership.current_lesson else '1.1' %} + {% set query_parameter = "?batch=" + membership.batch if membership and + membership.batch else "" %} + + {% if progress == 100 %} + + + {% elif course.upcoming %} + + + {% elif membership %} + + + {% else %} + + + {% endif %} + {% endif %}
- - {% if read_only %} - - {% else %} - - {% set lesson_index = get_lesson_index(membership.current_lesson) if membership and - membership.current_lesson else '1.1' %} - {% set query_parameter = "?batch=" + membership.batch if membership and - membership.batch else "" %} - - {% if progress == 100 %} - - - {% elif course.upcoming %} - - - {% elif membership %} - - - {% else %} - - - {% endif %} - {% endif %} -