Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
49e5e215
Commit
49e5e215
authored
Sep 13, 2016
by
Clinton Blackburn
Committed by
GitHub
Sep 13, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimized performance of the Affiliate Window endpoint (#322)
ECOM-5534
parent
d9c3d591
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
10 deletions
+9
-10
course_discovery/apps/api/v1/tests/test_views/test_affiliate_window.py
+5
-0
course_discovery/apps/api/v1/views.py
+4
-10
No files found.
course_discovery/apps/api/v1/tests/test_views/test_affiliate_window.py
View file @
49e5e215
...
@@ -45,7 +45,9 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
...
@@ -45,7 +45,9 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
def
test_affiliate_with_supported_seats
(
self
):
def
test_affiliate_with_supported_seats
(
self
):
""" Verify that endpoint returns course runs for verified and professional seats only. """
""" Verify that endpoint returns course runs for verified and professional seats only. """
with
self
.
assertNumQueries
(
11
):
response
=
self
.
client
.
get
(
self
.
affiliate_url
)
response
=
self
.
client
.
get
(
self
.
affiliate_url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
root
=
ET
.
fromstring
(
response
.
content
)
root
=
ET
.
fromstring
(
response
.
content
)
self
.
assertEqual
(
1
,
len
(
root
.
findall
(
'product'
)))
self
.
assertEqual
(
1
,
len
(
root
.
findall
(
'product'
)))
...
@@ -126,6 +128,8 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
...
@@ -126,6 +128,8 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
# Superusers can view all catalogs
# Superusers can view all catalogs
self
.
client
.
force_authenticate
(
superuser
)
self
.
client
.
force_authenticate
(
superuser
)
with
self
.
assertNumQueries
(
8
):
response
=
self
.
client
.
get
(
url
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
...
@@ -135,5 +139,6 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
...
@@ -135,5 +139,6 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
status_code
,
403
)
catalog
.
viewers
=
[
self
.
user
]
catalog
.
viewers
=
[
self
.
user
]
with
self
.
assertNumQueries
(
8
):
response
=
self
.
client
.
get
(
url
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
course_discovery/apps/api/v1/views.py
View file @
49e5e215
...
@@ -3,12 +3,10 @@ import logging
...
@@ -3,12 +3,10 @@ import logging
import
os
import
os
from
io
import
StringIO
from
io
import
StringIO
import
pytz
from
django.conf
import
settings
from
django.conf
import
settings
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth
import
get_user_model
from
django.core.management
import
call_command
from
django.core.management
import
call_command
from
django.db
import
transaction
from
django.db
import
transaction
from
django.db.models
import
Q
from
django.db.models.functions
import
Lower
from
django.db.models.functions
import
Lower
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.shortcuts
import
get_object_or_404
from
django.shortcuts
import
get_object_or_404
...
@@ -492,14 +490,10 @@ class AffiliateWindowViewSet(viewsets.ViewSet):
...
@@ -492,14 +490,10 @@ class AffiliateWindowViewSet(viewsets.ViewSet):
if
not
catalog
.
has_object_read_permission
(
request
):
if
not
catalog
.
has_object_read_permission
(
request
):
raise
PermissionDenied
raise
PermissionDenied
courses
=
catalog
.
courses
()
.
active
()
courses
=
catalog
.
courses
()
course_runs
=
CourseRun
.
objects
.
filter
(
course__in
=
courses
)
.
active
()
.
marketable
()
seats
=
Seat
.
objects
.
filter
(
seats
=
Seat
.
objects
.
filter
(
type__in
=
[
Seat
.
VERIFIED
,
Seat
.
PROFESSIONAL
])
.
filter
(
course_run__in
=
course_runs
)
(
Q
(
course_run__end__gte
=
datetime
.
datetime
.
now
(
pytz
.
UTC
))
|
Q
(
course_run__end__isnull
=
True
))
&
seats
=
seats
.
select_related
(
'course_run'
)
.
prefetch_related
(
'course_run__course'
,
'course_run__course__partner'
)
Q
(
course_run__course__in
=
courses
)
&
Q
(
type__in
=
[
Seat
.
VERIFIED
,
Seat
.
PROFESSIONAL
])
&
(
Q
(
course_run__enrollment_end__isnull
=
True
)
|
Q
(
course_run__enrollment_end__gte
=
datetime
.
datetime
.
now
(
pytz
.
UTC
)))
)
serializer
=
serializers
.
AffiliateWindowSerializer
(
seats
,
many
=
True
)
serializer
=
serializers
.
AffiliateWindowSerializer
(
seats
,
many
=
True
)
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
data
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment