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
bec6971a
Commit
bec6971a
authored
Feb 29, 2016
by
Bill DeRusha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Monkey patch django.db.models.options for faster cache expiry
parent
bd4cc57b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
2 deletions
+43
-2
cms/startup.py
+2
-1
common/djangoapps/monkey_patch/django_db_models_options.py
+39
-0
lms/startup.py
+2
-1
No files found.
cms/startup.py
View file @
bec6971a
...
@@ -9,7 +9,7 @@ settings.INSTALLED_APPS # pylint: disable=pointless-statement
...
@@ -9,7 +9,7 @@ settings.INSTALLED_APPS # pylint: disable=pointless-statement
from
openedx.core.lib.django_startup
import
autostartup
from
openedx.core.lib.django_startup
import
autostartup
import
django
import
django
from
monkey_patch
import
third_party_auth
from
monkey_patch
import
third_party_auth
,
django_db_models_options
import
xmodule.x_module
import
xmodule.x_module
import
cms.lib.xblock.runtime
import
cms.lib.xblock.runtime
...
@@ -22,6 +22,7 @@ def run():
...
@@ -22,6 +22,7 @@ def run():
Executed during django startup
Executed during django startup
"""
"""
third_party_auth
.
patch
()
third_party_auth
.
patch
()
django_db_models_options
.
patch
()
# Comprehensive theming needs to be set up before django startup,
# Comprehensive theming needs to be set up before django startup,
# because modifying django template paths after startup has no effect.
# because modifying django template paths after startup has no effect.
...
...
common/djangoapps/monkey_patch/django_db_models_options.py
0 → 100644
View file @
bec6971a
"""
Monkey patch implementation of the following _expire_cache performance improvement:
https://github.com/django/django/commit/7628f87e2b1ab4b8a881f06c8973be4c368aaa3d
Remove once we upgrade to a version of django which includes this fix natively!
NOTE: This is on django's master branch but is NOT currently part of any django 1.8 or 1.9 release.
"""
from
django.db.models.options
import
Options
def
patch
():
"""
Monkey-patch the Options class.
"""
def
_expire_cache
(
self
,
forward
=
True
,
reverse
=
True
):
# pylint: disable=missing-docstring
# This method is usually called by apps.cache_clear(), when the
# registry is finalized, or when a new field is added.
if
forward
:
for
cache_key
in
self
.
FORWARD_PROPERTIES
:
if
cache_key
in
self
.
__dict__
:
delattr
(
self
,
cache_key
)
if
reverse
and
not
self
.
abstract
:
for
cache_key
in
self
.
REVERSE_PROPERTIES
:
if
cache_key
in
self
.
__dict__
:
delattr
(
self
,
cache_key
)
self
.
_get_fields_cache
=
{}
# pylint: disable=protected-access
# Patch constants as a set instead of a list.
Options
.
FORWARD_PROPERTIES
=
{
'fields'
,
'many_to_many'
,
'concrete_fields'
,
'local_concrete_fields'
,
'_forward_fields_map'
}
Options
.
REVERSE_PROPERTIES
=
{
'related_objects'
,
'fields_map'
,
'_relation_tree'
}
# Patch the expire_cache method to utilize constant's new set data structure.
Options
.
_expire_cache
=
_expire_cache
# pylint: disable=protected-access
lms/startup.py
View file @
bec6971a
...
@@ -12,7 +12,7 @@ from openedx.core.lib.django_startup import autostartup
...
@@ -12,7 +12,7 @@ from openedx.core.lib.django_startup import autostartup
import
edxmako
import
edxmako
import
logging
import
logging
import
analytics
import
analytics
from
monkey_patch
import
third_party_auth
from
monkey_patch
import
third_party_auth
,
django_db_models_options
import
xmodule.x_module
import
xmodule.x_module
...
@@ -29,6 +29,7 @@ def run():
...
@@ -29,6 +29,7 @@ def run():
Executed during django startup
Executed during django startup
"""
"""
third_party_auth
.
patch
()
third_party_auth
.
patch
()
django_db_models_options
.
patch
()
# To override the settings before executing the autostartup() for python-social-auth
# To override the settings before executing the autostartup() for python-social-auth
if
settings
.
FEATURES
.
get
(
'ENABLE_THIRD_PARTY_AUTH'
,
False
):
if
settings
.
FEATURES
.
get
(
'ENABLE_THIRD_PARTY_AUTH'
,
False
):
...
...
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