##// END OF EJS Templates
Added media directory cache size
neko259 -
r1424:78342ab8 default
parent child Browse files
Show More
@@ -72,15 +72,20 b" def get_websocket_token(user_id='', time"
72 return token
72 return token
73
73
74
74
75 # TODO Test this carefully
75 def cached_result(key_method=None):
76 def cached_result(key_method=None):
76 """
77 """
77 Caches method result in the Django's cache system, persisted by object name,
78 Caches method result in the Django's cache system, persisted by object name,
78 object name and model id if object is a Django model.
79 object name, model id if object is a Django model, args and kwargs if any.
79 """
80 """
80 def _cached_result(function):
81 def _cached_result(function):
81 def inner_func(obj, *args, **kwargs):
82 def inner_func(obj, *args, **kwargs):
82 # TODO Include method arguments to the cache key
83 cache_key_params = [obj.__class__.__name__, function.__name__]
83 cache_key_params = [obj.__class__.__name__, function.__name__]
84
85 cache_key_params += args
86 for key, value in kwargs:
87 cache_key_params.append(key + ':' + value)
88
84 if isinstance(obj, Model):
89 if isinstance(obj, Model):
85 cache_key_params.append(str(obj.id))
90 cache_key_params.append(str(obj.id))
86
91
@@ -4,6 +4,7 b' from django.shortcuts import render'
4
4
5 import neboard
5 import neboard
6 from boards.authors import authors
6 from boards.authors import authors
7 from boards.utils import cached_result
7 from boards.views.base import BaseBoardView
8 from boards.views.base import BaseBoardView
8 from boards.models import Post
9 from boards.models import Post
9
10
@@ -23,6 +24,7 b' class AuthorsView(BaseBoardView):'
23
24
24 return render(request, 'boards/authors.html', params)
25 return render(request, 'boards/authors.html', params)
25
26
27 @cached_result()
26 def _get_directory_size(self, directory):
28 def _get_directory_size(self, directory):
27 total_size = 0
29 total_size = 0
28 for dirpath, dirnames, filenames in os.walk(directory):
30 for dirpath, dirnames, filenames in os.walk(directory):
General Comments 0
You need to be logged in to leave comments. Login now