Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.73.1 #1879

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release Notes
=============

Version 0.73.1
--------------

- 1869: Course program api performance improvements (#1872)
- Remove duplicate catalog URL path (#1871)

Version 0.73.0 (Released September 11, 2023)
--------------

Expand Down
3 changes: 2 additions & 1 deletion cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.core.exceptions import ValidationError
from django.core.serializers.json import DjangoJSONEncoder
from django.db import models
from django.utils.functional import cached_property
from django.forms import ChoiceField, DecimalField
from django.http import Http404
from django.template.response import TemplateResponse
Expand Down Expand Up @@ -1084,7 +1085,7 @@ class CoursePage(ProductPage):
)
]

@property
@cached_property
def product(self):
"""Gets the product associated with this page"""
return self.course
Expand Down
24 changes: 3 additions & 21 deletions cms/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class CoursePageSerializer(serializers.ModelSerializer):
description = serializers.SerializerMethodField()
current_price = serializers.SerializerMethodField()
instructors = serializers.SerializerMethodField()
live = serializers.SerializerMethodField()
effort = serializers.SerializerMethodField()
length = serializers.SerializerMethodField()

Expand Down Expand Up @@ -76,28 +75,14 @@ def get_financial_assistance_form_url(self, instance):
else ""
)

def get_next_run_id(self, instance):
"""Get next run id"""
run = instance.course.first_unexpired_run
return run.id if run is not None else None

def get_description(self, instance):
return bleach.clean(instance.description, tags=[], strip=True)

def get_current_price(self, instance):
next_run = self.get_next_run_id(instance)

if next_run is None:
return None

course_ct = ContentType.objects.get(app_label="courses", model="courserun")

relevant_product = (
Product.objects.filter(
content_type=course_ct, object_id=next_run, is_active=True
)
.order_by("-price")
.first()
instance.product.active_products.filter().order_by("-price").first()
if instance.product.active_products
else None
)
return relevant_product.price if relevant_product else None

Expand All @@ -120,9 +105,6 @@ def get_instructors(self, instance):

return returnable_members

def get_live(self, instance):
return instance.live

def get_effort(self, instance):
return (
bleach.clean(instance.effort, tags=[], strip=True)
Expand Down
2 changes: 0 additions & 2 deletions courses/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@
CourseRunCertificate,
CourseRunEnrollment,
CourseRunGrade,
Program,
ProgramCertificate,
ProgramEnrollment,
ProgramRequirement,
ProgramRequirementNodeType,
)
from courses.tasks import subscribe_edx_course_emails
from courses.utils import (
Expand Down
22 changes: 22 additions & 0 deletions courses/migrations/0043_course_program_live_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.20 on 2023-09-10 11:40

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("courses", "0042_add_ordering_to_course_and_program"),
]

operations = [
migrations.AlterField(
model_name="course",
name="live",
field=models.BooleanField(db_index=True, default=False),
),
migrations.AlterField(
model_name="program",
name="live",
field=models.BooleanField(db_index=True, default=False),
),
]
17 changes: 10 additions & 7 deletions courses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class Meta:
readable_id = models.CharField(
max_length=255, unique=True, validators=[validate_url_path_field]
)
live = models.BooleanField(default=False)
live = models.BooleanField(default=False, db_index=True)
program_type = models.CharField(
max_length=255,
default="Series",
Expand Down Expand Up @@ -295,7 +295,7 @@ def save(self, *args, **kwargs):
program=self, node_type=ProgramRequirementNodeType.PROGRAM_ROOT.value
)

@property
@cached_property
def courses(self):
"""
Returns the courses associated with this program via the requirements
Expand All @@ -315,7 +315,7 @@ def courses(self):
path__startswith=op.path,
node_type=ProgramRequirementNodeType.COURSE,
)
.select_related("course", "course__page")
.select_related("course")
.all()
)

Expand Down Expand Up @@ -436,7 +436,7 @@ class Meta:
readable_id = models.CharField(
max_length=255, unique=True, validators=[validate_url_path_field]
)
live = models.BooleanField(default=False)
live = models.BooleanField(default=False, db_index=True)
departments = models.ManyToManyField(Department, blank=True)
flexible_prices = GenericRelation(
"flexiblepricing.FlexiblePrice",
Expand All @@ -449,7 +449,7 @@ class Meta:
content_type_field="courseware_content_type",
)

@property
@cached_property
def course_number(self):
"""
Returns:
Expand Down Expand Up @@ -523,6 +523,7 @@ def programs(self):
ProgramRequirement.objects.filter(
node_type=ProgramRequirementNodeType.COURSE, course=self
)
.all()
.distinct("program_id")
.order_by("program_id")
.values_list("program_id", flat=True)
Expand Down Expand Up @@ -575,7 +576,7 @@ class CourseRun(TimestampedModel):

objects = CourseRunQuerySet.as_manager()
course = models.ForeignKey(
Course, on_delete=models.CASCADE, related_name="courseruns"
Course, on_delete=models.CASCADE, related_name="courseruns", db_index=True
)
# product = GenericRelation(Product, related_query_name="course_run")
title = models.CharField(
Expand Down Expand Up @@ -633,7 +634,9 @@ class CourseRun(TimestampedModel):

live = models.BooleanField(default=False)
is_self_paced = models.BooleanField(default=False)
products = GenericRelation("ecommerce.Product", related_query_name="courseruns")
products = GenericRelation(
"ecommerce.Product", related_query_name="courserunproducts"
)

class Meta:
unique_together = ("course", "run_tag")
Expand Down
Loading
Loading