Add type check for cache
This commit is contained in:
parent
f1ba0e79c1
commit
0ea822f7a0
10 changed files with 35 additions and 13 deletions
|
@ -23,7 +23,7 @@ class BookMark(models.Model):
|
|||
linked_object = GenericForeignKey("content_type", "object_id")
|
||||
|
||||
@cache_wrapper(prefix="BMgb")
|
||||
def get_bookmark(self, user):
|
||||
def is_bookmarked_by(self, user):
|
||||
return MakeBookMark.objects.filter(bookmark=self, user=user).exists()
|
||||
|
||||
class Meta:
|
||||
|
@ -53,7 +53,7 @@ class MakeBookMark(models.Model):
|
|||
verbose_name_plural = _("make bookmarks")
|
||||
|
||||
|
||||
@cache_wrapper(prefix="gocb")
|
||||
@cache_wrapper(prefix="gocb", expected_type=BookMark)
|
||||
def _get_or_create_bookmark(content_type, object_id):
|
||||
bookmark, created = BookMark.objects.get_or_create(
|
||||
content_type=content_type,
|
||||
|
@ -70,5 +70,5 @@ class Bookmarkable:
|
|||
|
||||
|
||||
def dirty_bookmark(bookmark, profile):
|
||||
bookmark.get_bookmark.dirty(bookmark, profile)
|
||||
bookmark.is_bookmarked_by.dirty(bookmark, profile)
|
||||
_get_or_create_bookmark.dirty(bookmark.content_type, bookmark.object_id)
|
||||
|
|
|
@ -133,7 +133,7 @@ class BlogPost(models.Model, PageVotable, Bookmarkable):
|
|||
and self.authors.filter(id=user.profile.id).exists()
|
||||
)
|
||||
|
||||
@cache_wrapper(prefix="BPga")
|
||||
@cache_wrapper(prefix="BPga", expected_type=models.query.QuerySet)
|
||||
def get_authors(self):
|
||||
return self.authors.only("id")
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class PageVoteVoter(models.Model):
|
|||
verbose_name_plural = _("pagevote votes")
|
||||
|
||||
|
||||
@cache_wrapper(prefix="gocp")
|
||||
@cache_wrapper(prefix="gocp", expected_type=PageVote)
|
||||
def _get_or_create_pagevote(content_type, object_id):
|
||||
pagevote, created = PageVote.objects.get_or_create(
|
||||
content_type=content_type,
|
||||
|
|
|
@ -440,7 +440,7 @@ class Problem(models.Model, PageVotable, Bookmarkable):
|
|||
"profile_id", flat=True
|
||||
)
|
||||
|
||||
@cache_wrapper(prefix="Pga")
|
||||
@cache_wrapper(prefix="Pga", expected_type=models.query.QuerySet)
|
||||
def get_authors(self):
|
||||
return self.authors.only("id")
|
||||
|
||||
|
|
|
@ -581,7 +581,7 @@ def on_user_save(sender, instance, **kwargs):
|
|||
pass
|
||||
|
||||
|
||||
@cache_wrapper(prefix="Pgbi3")
|
||||
@cache_wrapper(prefix="Pgbi3", expected_type=dict)
|
||||
def _get_basic_info(profile_id):
|
||||
profile = (
|
||||
Profile.objects.select_related("user")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue