Have tags/attrs.all() switch to direct query on AGGRESSIVE_TYPECLASS_CACHE=False. Resolves #2007
This commit is contained in:
parent
d806909f33
commit
c428eb72a5
2 changed files with 32 additions and 16 deletions
|
|
@ -235,19 +235,23 @@ class AttributeHandler(object):
|
||||||
# full cache was run on all attributes
|
# full cache was run on all attributes
|
||||||
self._cache_complete = False
|
self._cache_complete = False
|
||||||
|
|
||||||
def _fullcache(self):
|
def _query_all(self):
|
||||||
"""Cache all attributes of this object"""
|
"Fetch all Attributes on this object"
|
||||||
if not _TYPECLASS_AGGRESSIVE_CACHE:
|
|
||||||
return
|
|
||||||
query = {
|
query = {
|
||||||
"%s__id" % self._model: self._objid,
|
"%s__id" % self._model: self._objid,
|
||||||
"attribute__db_model__iexact": self._model,
|
"attribute__db_model__iexact": self._model,
|
||||||
"attribute__db_attrtype": self._attrtype,
|
"attribute__db_attrtype": self._attrtype,
|
||||||
}
|
}
|
||||||
attrs = [
|
return [
|
||||||
conn.attribute
|
conn.attribute
|
||||||
for conn in getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query)
|
for conn in getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def _fullcache(self):
|
||||||
|
"""Cache all attributes of this object"""
|
||||||
|
if not _TYPECLASS_AGGRESSIVE_CACHE:
|
||||||
|
return
|
||||||
|
attrs = self._query_all()
|
||||||
self._cache = dict(
|
self._cache = dict(
|
||||||
(
|
(
|
||||||
"%s-%s"
|
"%s-%s"
|
||||||
|
|
@ -776,9 +780,13 @@ class AttributeHandler(object):
|
||||||
their values!) in the handler.
|
their values!) in the handler.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self._cache_complete:
|
if _TYPECLASS_AGGRESSIVE_CACHE:
|
||||||
self._fullcache()
|
if not self._cache_complete:
|
||||||
attrs = sorted([attr for attr in self._cache.values() if attr], key=lambda o: o.id)
|
self._fullcache()
|
||||||
|
attrs = sorted([attr for attr in self._cache.values() if attr], key=lambda o: o.id)
|
||||||
|
else:
|
||||||
|
attrs = sorted([attr for attr in self._query_all() if attr], key=lambda o: o.id)
|
||||||
|
|
||||||
if accessing_obj:
|
if accessing_obj:
|
||||||
return [
|
return [
|
||||||
attr
|
attr
|
||||||
|
|
|
||||||
|
|
@ -124,19 +124,23 @@ class TagHandler(object):
|
||||||
# full cache was run on all tags
|
# full cache was run on all tags
|
||||||
self._cache_complete = False
|
self._cache_complete = False
|
||||||
|
|
||||||
def _fullcache(self):
|
def _query_all(self):
|
||||||
"Cache all tags of this object"
|
"Get all tags for this objects"
|
||||||
if not _TYPECLASS_AGGRESSIVE_CACHE:
|
|
||||||
return
|
|
||||||
query = {
|
query = {
|
||||||
"%s__id" % self._model: self._objid,
|
"%s__id" % self._model: self._objid,
|
||||||
"tag__db_model": self._model,
|
"tag__db_model": self._model,
|
||||||
"tag__db_tagtype": self._tagtype,
|
"tag__db_tagtype": self._tagtype,
|
||||||
}
|
}
|
||||||
tags = [
|
return [
|
||||||
conn.tag
|
conn.tag
|
||||||
for conn in getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query)
|
for conn in getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def _fullcache(self):
|
||||||
|
"Cache all tags of this object"
|
||||||
|
if not _TYPECLASS_AGGRESSIVE_CACHE:
|
||||||
|
return
|
||||||
|
tags = self._query_all()
|
||||||
self._cache = dict(
|
self._cache = dict(
|
||||||
(
|
(
|
||||||
"%s-%s"
|
"%s-%s"
|
||||||
|
|
@ -425,9 +429,13 @@ class TagHandler(object):
|
||||||
`return_key_and_category` is set.
|
`return_key_and_category` is set.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self._cache_complete:
|
if _TYPECLASS_AGGRESSIVE_CACHE:
|
||||||
self._fullcache()
|
if not self._cache_complete:
|
||||||
tags = sorted(self._cache.values())
|
self._fullcache()
|
||||||
|
tags = sorted(self._cache.values())
|
||||||
|
else:
|
||||||
|
tags = sorted(self._query_all())
|
||||||
|
|
||||||
if return_key_and_category:
|
if return_key_and_category:
|
||||||
# return tuple (key, category)
|
# return tuple (key, category)
|
||||||
return [(to_str(tag.db_key), tag.db_category) for tag in tags]
|
return [(to_str(tag.db_key), tag.db_category) for tag in tags]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue