Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
1624720f
Commit
1624720f
authored
Feb 20, 2015
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop hitting the database when no courses are blocked.
parent
0e3f40b9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
2 deletions
+12
-2
common/djangoapps/embargo/models.py
+2
-2
common/djangoapps/embargo/tests/test_api.py
+10
-0
No files found.
common/djangoapps/embargo/models.py
View file @
1624720f
...
...
@@ -156,7 +156,7 @@ class RestrictedCourse(models.Model):
Cache all restricted courses and returns the list of course_keys that are restricted
"""
restricted_courses
=
cache
.
get
(
cls
.
COURSE_LIST_CACHE_KEY
)
if
not
restricted_courses
:
if
restricted_courses
is
None
:
restricted_courses
=
list
(
RestrictedCourse
.
objects
.
values_list
(
'course_key'
,
flat
=
True
))
cache
.
set
(
cls
.
COURSE_LIST_CACHE_KEY
,
restricted_courses
)
return
restricted_courses
...
...
@@ -413,7 +413,7 @@ class CountryAccessRule(models.Model):
"""
cache_key
=
cls
.
CACHE_KEY
.
format
(
course_key
=
course_id
)
allowed_countries
=
cache
.
get
(
cache_key
)
if
not
allowed_countries
:
if
allowed_countries
is
None
:
allowed_countries
=
cls
.
_get_country_access_list
(
course_id
)
cache
.
set
(
cache_key
,
allowed_countries
)
...
...
common/djangoapps/embargo/tests/test_api.py
View file @
1624720f
...
...
@@ -166,6 +166,16 @@ class EmbargoCheckAccessApiTests(ModuleStoreTestCase):
with
self
.
assertNumQueries
(
0
):
embargo_api
.
check_course_access
(
self
.
course
.
id
,
user
=
self
.
user
,
ip_address
=
'0.0.0.0'
)
def
test_caching_no_restricted_courses
(
self
):
RestrictedCourse
.
objects
.
all
()
.
delete
()
cache
.
clear
()
with
self
.
assertNumQueries
(
1
):
embargo_api
.
check_course_access
(
self
.
course
.
id
,
user
=
self
.
user
,
ip_address
=
'0.0.0.0'
)
with
self
.
assertNumQueries
(
0
):
embargo_api
.
check_course_access
(
self
.
course
.
id
,
user
=
self
.
user
,
ip_address
=
'0.0.0.0'
)
@ddt.ddt
@override_settings
(
MODULESTORE
=
MODULESTORE_CONFIG
)
...
...
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