# HG changeset patch # User neko259 # Date 2017-12-14 10:37:27 # Node ID 1acac3a8bb5144fa573616ee800916ac8fea1655 # Parent 6c504f97e556ea813cc847859cbf165ba9f05855 Cache tripcode view diff --git a/boards/abstracts/tripcode.py b/boards/abstracts/tripcode.py --- a/boards/abstracts/tripcode.py +++ b/boards/abstracts/tripcode.py @@ -1,17 +1,22 @@ from django.urls import reverse +from boards.utils import cached_result + TRIPCODE_VIEW = '' \ '{short_text}' +SHORT_TEXT_CHARS = 8 +COLOR_CHARS = 6 + class Tripcode: def __init__(self, code_str): self.tripcode = code_str def get_color(self): - return self.tripcode[:6] + return self.tripcode[:COLOR_CHARS] def get_background(self): code = self.get_color() @@ -27,13 +32,18 @@ class Tripcode: return result def get_short_text(self): - return self.tripcode[:8] + return self.tripcode[:SHORT_TEXT_CHARS] def get_full_text(self): return self.tripcode + def _get_cache_key(self): + return [self.tripcode] + + @cached_result(key_method=_get_cache_key) def get_view(self): return TRIPCODE_VIEW.format(url=reverse('feed'), short_text=self.get_short_text(), full_text=self.get_full_text(), color=self.get_color()) +