From: hernani Date: Mon, 19 Apr 2010 12:08:36 +0000 (+0000) Subject: several improvements in the caching system X-Git-Tag: live~1019 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/9b450de133375fb612625b826f1920b672ab2acc several improvements in the caching system git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@55 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/models/base.py b/forum/models/base.py index 78f1242..08ccb44 100644 --- a/forum/models/base.py +++ b/forum/models/base.py @@ -24,7 +24,8 @@ class CachedManager(models.Manager): def get(self, *args, **kwargs): try: - pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact') or k.endswith('_ptr__pk')][0] + pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact' + ) or k.endswith('_ptr__pk') or k.endswith('_ptr__id')][0] except: pk = None diff --git a/forum/models/meta.py b/forum/models/meta.py index c01c018..86a479c 100644 --- a/forum/models/meta.py +++ b/forum/models/meta.py @@ -20,7 +20,7 @@ class Vote(MetaContent, CancelableContent, UserContent): return '[%s] voted at %s: %s' %(self.user, self.voted_at, self.vote) def _update_post_vote_count(self, diff): - post = self.node + post = self.node.leaf field = self.vote == 1 and 'vote_up_count' or 'vote_down_count' post.__dict__[field] = post.__dict__[field] + diff post.save() diff --git a/forum/views/admin.py b/forum/views/admin.py index 3fa02bc..7a29922 100644 --- a/forum/views/admin.py +++ b/forum/views/admin.py @@ -159,6 +159,7 @@ def go_defaults(request): @super_user_required def recalculate_denormalized(request): for n in Node.objects.all(): + n = n.leaf n.vote_up_count = n.votes.filter(canceled=False, vote=1).count() n.vote_down_count = n.votes.filter(canceled=False, vote=-1).count() n.save() diff --git a/forum/views/commands.py b/forum/views/commands.py index 4ff80f8..b129911 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -63,7 +63,7 @@ class CannotDoubleActionException(Exception): @command def vote_post(request, id, vote_type): - post = get_object_or_404(Node, id=id) + post = get_object_or_404(Node, id=id).leaf vote_score = vote_type == 'up' and 1 or -1 user = request.user diff --git a/forum/views/readers.py b/forum/views/readers.py index 879dbcf..ac20dae 100644 --- a/forum/views/readers.py +++ b/forum/views/readers.py @@ -210,7 +210,7 @@ def match_question_slug(slug): def question(request, id, slug): try: - question = Question.objects.get(id=id) + question = Question.objects.get(node_type="question", id=id) except: question = match_question_slug(slug) if question is not None: