Stop memoizing the filter input and output to prevent memory leakage. Fixes #140 and #139.

This commit is contained in:
Jannis Leidel
2011-11-02 13:29:39 +01:00
parent 44f1b04d1d
commit 74cc5bd1c8
2 changed files with 3 additions and 33 deletions

View File

@@ -17,7 +17,7 @@ from compressor.filters import CompilerFilter
from compressor.storage import default_storage, compressor_file_storage
from compressor.signals import post_compress
from compressor.utils import get_class, staticfiles
from compressor.utils.decorators import cached_property, memoize
from compressor.utils.decorators import cached_property
# Some constants for nicer handling.
SOURCE_HUNK, SOURCE_FILE = 'inline', 'file'
@@ -119,7 +119,6 @@ class Compressor(object):
return get_hexdigest(''.join(
[self.content] + self.mtimes).encode(self.charset), 12)
@memoize
def hunks(self, mode='file', forced=False):
"""
The heart of content parsing, iterates of the
@@ -157,7 +156,6 @@ class Compressor(object):
else:
yield mode, self.parser.elem_str(elem)
@memoize
def filtered_output(self, content):
"""
Passes the concatenated content to the 'output' methods
@@ -165,7 +163,6 @@ class Compressor(object):
"""
return self.filter(content, method=METHOD_OUTPUT)
@memoize
def filtered_input(self, mode='file', forced=False):
"""
Passes each hunk (file or code) to the 'input' methods
@@ -267,6 +264,7 @@ class Compressor(object):
final_context.update(self.context)
final_context.update(context)
final_context.update(self.extra_context)
post_compress.send(sender='django-compressor', type=self.type, mode=mode, context=final_context)
post_compress.send(sender='django-compressor', type=self.type,
mode=mode, context=final_context)
return render_to_string("compressor/%s_%s.html" %
(self.type, mode), final_context)

View File

@@ -1,31 +1,3 @@
import functools
class memoize(object):
def __init__ (self, func):
self.func = func
def __call__ (self, *args, **kwargs):
if (args, str(kwargs)) in self.__dict__:
value = self.__dict__[args, str(kwargs)]
else:
value = self.func(*args, **kwargs)
self.__dict__[args, str(kwargs)] = value
return value
def __repr__(self):
"""
Return the function's docstring.
"""
return self.func.__doc__ or ''
def __get__(self, obj, objtype):
"""
Support instance methods.
"""
return functools.partial(self.__call__, obj)
class cached_property(object):
"""Property descriptor that caches the return value
of the get function.