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
009bd230
Commit
009bd230
authored
Jul 31, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save LazyLoadingDict in case we do want it later
parent
58543bd8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
60 deletions
+58
-60
common/lib/xmodule/lazy_dict.py
+58
-0
common/lib/xmodule/xmodule/xml_module.py
+0
-60
No files found.
common/lib/xmodule/lazy_dict.py
0 → 100644
View file @
009bd230
from
collections
import
MutableMapping
class
LazyLoadingDict
(
MutableMapping
):
"""
A dictionary object that lazily loads its contents from a provided
function on reads (of members that haven't already been set).
"""
def
__init__
(
self
,
loader
):
'''
On the first read from this dictionary, it will call loader() to
populate its contents. loader() must return something dict-like. Any
elements set before the first read will be preserved.
'''
self
.
_contents
=
{}
self
.
_loaded
=
False
self
.
_loader
=
loader
self
.
_deleted
=
set
()
def
__getitem__
(
self
,
name
):
if
not
(
self
.
_loaded
or
name
in
self
.
_contents
or
name
in
self
.
_deleted
):
self
.
load
()
return
self
.
_contents
[
name
]
def
__setitem__
(
self
,
name
,
value
):
self
.
_contents
[
name
]
=
value
self
.
_deleted
.
discard
(
name
)
def
__delitem__
(
self
,
name
):
del
self
.
_contents
[
name
]
self
.
_deleted
.
add
(
name
)
def
__contains__
(
self
,
name
):
self
.
load
()
return
name
in
self
.
_contents
def
__len__
(
self
):
self
.
load
()
return
len
(
self
.
_contents
)
def
__iter__
(
self
):
self
.
load
()
return
iter
(
self
.
_contents
)
def
__repr__
(
self
):
self
.
load
()
return
repr
(
self
.
_contents
)
def
load
(
self
):
if
self
.
_loaded
:
return
loaded_contents
=
self
.
_loader
()
loaded_contents
.
update
(
self
.
_contents
)
self
.
_contents
=
loaded_contents
self
.
_loaded
=
True
common/lib/xmodule/xmodule/xml_module.py
View file @
009bd230
...
...
@@ -11,66 +11,6 @@ import os
log
=
logging
.
getLogger
(
__name__
)
# # TODO (cpennington): This was implemented in an attempt to improve performance,
# # but the actual improvement wasn't measured (and it was implemented late at night).
# # We should check if it hurts, and whether there's a better way of doing lazy loading
# class LazyLoadingDict(MutableMapping):
# """
# A dictionary object that lazily loads its contents from a provided
# function on reads (of members that haven't already been set).
# """
# def __init__(self, loader):
# '''
# On the first read from this dictionary, it will call loader() to
# populate its contents. loader() must return something dict-like. Any
# elements set before the first read will be preserved.
# '''
# self._contents = {}
# self._loaded = False
# self._loader = loader
# self._deleted = set()
# def __getitem__(self, name):
# if not (self._loaded or name in self._contents or name in self._deleted):
# self.load()
# return self._contents[name]
# def __setitem__(self, name, value):
# self._contents[name] = value
# self._deleted.discard(name)
# def __delitem__(self, name):
# del self._contents[name]
# self._deleted.add(name)
# def __contains__(self, name):
# self.load()
# return name in self._contents
# def __len__(self):
# self.load()
# return len(self._contents)
# def __iter__(self):
# self.load()
# return iter(self._contents)
# def __repr__(self):
# self.load()
# return repr(self._contents)
# def load(self):
# if self._loaded:
# return
# loaded_contents = self._loader()
# loaded_contents.update(self._contents)
# self._contents = loaded_contents
# self._loaded = True
_AttrMapBase
=
namedtuple
(
'_AttrMap'
,
'metadata_key to_metadata from_metadata'
)
...
...
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