magic-removal: Removed caching hack for managers, disabling caching for everything except related objects

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2154 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Luke Plant 2006-01-29 01:09:10 +00:00
parent a33aa41fbf
commit d580b42d45
2 changed files with 14 additions and 17 deletions

View File

@ -370,10 +370,4 @@ class ManagerDescriptor(object):
if instance != None:
raise AttributeError, "Manager isn't accessible via %s instances" % type.__name__
# HACK
# We need a new instance every time. Otherwise, the cache that
# the manager keeps never gets dropped, which is pain for memory usage,
# and concurrency and means that queries don't get updated when you do
# a model_obj.save(). (This hack helps some tests to pass, but isn't a real fix)
#return self.manager.__class__()
return copy.deepcopy(self.manager)
return self.manager

View File

@ -67,6 +67,7 @@ class QuerySet(object):
self._tables = None
self._offset = None
self._limit = None
self._use_cache = False
def filter(self, **kwargs):
"""Returns a new query instance with the query arguments
@ -240,21 +241,24 @@ class QuerySet(object):
return select, " ".join(sql), params
def _fetch_data(self):
if self._use_cache:
if self._result_cache is None:
self._result_cache = list(self.get_iterator())
return self._result_cache
else:
return list(self.get_iterator())
def __iter__(self):
"""Gets an iterator for the data"""
# Fetch the data or use get_iterator? If not, we can't
# do sequence operations - or doing so will require re-fetching
# Also, lots of things in current template system break if
# Also, lots of things in current template system break if we
# don't get it all.
self._fetch_data()
return iter(self._result_cache)
return iter(self._fetch_data())
def __len__(self):
self._fetch_data()
return len(self._result_cache)
return len(self._fetch_data())
def __getitem__(self, k):
"""Retrieve an item or slice from the set of results"""
@ -278,8 +282,7 @@ class QuerySet(object):
else:
# TODO: possibly use a new query which just gets one item
# if we haven't already got them all?
self._fetch_data()
return self._result_cache[k]
return self._fetch_data()[k]
def get_iterator(self):
# self._select is a dictionary, and dictionaries' key order is