git.ithinksw.org
/
philo.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6ffd478
)
Lazy-eval the values of AttributeValues instead of loading them all during AttributeM...
author
Stephen Burrows
<stephen.r.burrows@gmail.com>
Thu, 21 Jul 2011 20:39:28 +0000
(16:39 -0400)
committer
Stephen Burrows
<stephen.r.burrows@gmail.com>
Thu, 21 Jul 2011 20:39:28 +0000
(16:39 -0400)
philo/utils/entities.py
patch
|
blob
|
history
diff --git
a/philo/utils/entities.py
b/philo/utils/entities.py
index
754a5dc
..
c7b14b7
100644
(file)
--- a/
philo/utils/entities.py
+++ b/
philo/utils/entities.py
@@
-1,8
+1,11
@@
+from functools import partial
from UserDict import DictMixin
from django.db import models
from django.contrib.contenttypes.models import ContentType
from UserDict import DictMixin
from django.db import models
from django.contrib.contenttypes.models import ContentType
+from philo.utils.lazycompat import SimpleLazyObject
+
### AttributeMappers
### AttributeMappers
@@
-91,7
+94,11
@@
class AttributeMapper(object, DictMixin):
for ct_pk, pks in value_lookups.items():
values_bulk[ct_pk] = ContentType.objects.get_for_id(ct_pk).model_class().objects.in_bulk(pks)
for ct_pk, pks in value_lookups.items():
values_bulk[ct_pk] = ContentType.objects.get_for_id(ct_pk).model_class().objects.in_bulk(pks)
- self._cache.update(dict([(a.key, getattr(values_bulk[a.value_content_type_id].get(a.value_object_id), 'value', None)) for a in attributes]))
+ self._cache.update(dict([
+ (
+ a.key,
+ SimpleLazyObject(partial(getattr, values_bulk[a.value_content_type_id].get(a.value_object_id), 'value', None))
+ ) for a in attributes]))
self._cache_filled = True
def clear_cache(self):
self._cache_filled = True
def clear_cache(self):