|
2 | 2 | from django.contrib.contenttypes.models import ContentType |
3 | 3 | from django.core.cache import cache |
4 | 4 |
|
5 | | -from core.constants import VIEWS_CACHING_TIMEOUT, LIKES_CACHING_TIMEOUT |
| 5 | +from core.constants import VIEWS_CACHING_TIMEOUT |
6 | 6 | from core.models import Like, View, Link |
7 | 7 |
|
8 | 8 | User = get_user_model() |
@@ -36,15 +36,18 @@ def get_fans(obj): |
36 | 36 |
|
37 | 37 | def get_likes_count(obj): |
38 | 38 | obj_type = ContentType.objects.get_for_model(obj) |
39 | | - # cache this |
40 | | - likes_count = cache.get(f"likes_count_{obj_type}_{obj.id}") |
41 | | - if likes_count is None: |
42 | | - likes_count = User.objects.filter( |
43 | | - likes__content_type=obj_type, likes__object_id=obj.id |
44 | | - ).count() |
45 | | - # cache for LIKES_CACHING_TIMEOUT seconds |
46 | | - cache.set(f"likes_count_{obj_type}_{obj.id}", likes_count, LIKES_CACHING_TIMEOUT) |
47 | | - return likes_count |
| 39 | + # todo: temp comment |
| 40 | + # likes_count = cache.get(f"likes_count_{obj_type}_{obj.id}") |
| 41 | + # if likes_count is None: |
| 42 | + # likes_count = User.objects.filter( |
| 43 | + # likes__content_type=obj_type, likes__object_id=obj.id |
| 44 | + # ).count() |
| 45 | + # # cache for LIKES_CACHING_TIMEOUT seconds |
| 46 | + # cache.set(f"likes_count_{obj_type}_{obj.id}", likes_count, LIKES_CACHING_TIMEOUT) |
| 47 | + return User.objects.filter( |
| 48 | + likes__content_type=obj_type, likes__object_id=obj.id |
| 49 | + ).count() |
| 50 | + # return likes_count |
48 | 51 |
|
49 | 52 |
|
50 | 53 | def set_like(obj, user, is_liked): |
|
0 commit comments