Caching and refactors
This commit is contained in:
parent
67b06d7856
commit
8f1c8d6c96
33 changed files with 485 additions and 381 deletions
|
@ -20,6 +20,7 @@ from judge.models.interface import BlogPost
|
|||
from judge.models.problem import Problem, Solution
|
||||
from judge.models.profile import Profile
|
||||
from judge.utils.cachedict import CacheDict
|
||||
from judge.caching import cache_wrapper
|
||||
|
||||
|
||||
__all__ = ["Comment", "CommentLock", "CommentVote", "Notification"]
|
||||
|
@ -75,16 +76,16 @@ class Comment(MPTTModel):
|
|||
queryset = (
|
||||
cls.objects.filter(hidden=False)
|
||||
.select_related("author__user")
|
||||
.defer("author__about", "body")
|
||||
.defer("author__about")
|
||||
.order_by("-id")
|
||||
)
|
||||
|
||||
if organization:
|
||||
queryset = queryset.filter(author__in=organization.members.all())
|
||||
|
||||
problem_access = CacheDict(lambda p: p.is_accessible_by(user))
|
||||
object_access = CacheDict(lambda p: p.is_accessible_by(user))
|
||||
contest_access = CacheDict(lambda c: c.is_accessible_by(user))
|
||||
blog_access = CacheDict(lambda b: b.can_see(user))
|
||||
blog_access = CacheDict(lambda b: b.is_accessible_by(user))
|
||||
|
||||
if n == -1:
|
||||
n = len(queryset)
|
||||
|
@ -174,3 +175,10 @@ class CommentLock(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return str(self.page)
|
||||
|
||||
|
||||
@cache_wrapper(prefix="gcc")
|
||||
def get_visible_comment_count(content_type, object_id):
|
||||
return Comment.objects.filter(
|
||||
content_type=content_type, object_id=object_id, hidden=False
|
||||
).count()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue