Rafał Pitoń 10 years ago
parent
commit
440471ecb9
2 changed files with 20 additions and 3 deletions
  1. 6 1
      misago/threads/counts.py
  2. 14 2
      misago/threads/tests/test_counters.py

+ 6 - 1
misago/threads/counts.py

@@ -32,7 +32,10 @@ class BaseCounter(object):
         return count['threads']
 
     def is_cache_valid(self, cache):
-        return cache.get('expires', 0) > time()
+        if cache.get('expires', 0) > time():
+            return cache.get('user') == self.user.pk
+        else:
+            return False
 
     def get_expiration_timestamp(self):
         return time() + settings.MISAGO_CONTENT_COUNTING_FREQUENCY * 60
@@ -46,6 +49,7 @@ class BaseCounter(object):
     def set(self, count):
         self.count = count
         self.session[self.name] = {
+            'user': self.user.pk,
             'threads': count,
             'expires': self.get_expiration_timestamp()
         }
@@ -54,6 +58,7 @@ class BaseCounter(object):
         if self.count > 0:
             self.count -= 1
             self.session[self.name] = {
+                'user': self.user.pk,
                 'threads': self.count,
                 'expires': self.session[self.name]['expires']
             }

+ 14 - 2
misago/threads/tests/test_counters.py

@@ -38,8 +38,20 @@ class TestNewThreadsCount(AuthenticatedUserTestCase):
         """is_cache_valid returns valid value for different caches"""
         counter = NewThreadsCount(self.user, {})
 
-        self.assertTrue(counter.is_cache_valid({'expires': time() + 15}))
-        self.assertFalse(counter.is_cache_valid({'expires': time() - 15}))
+        self.assertTrue(counter.is_cache_valid({
+            'expires': time() + 15,
+            'user': self.user.pk
+        }))
+
+        self.assertFalse(counter.is_cache_valid({
+            'expires': time() - 15,
+            'user': self.user.pk
+        }))
+
+        self.assertFalse(counter.is_cache_valid({
+            'expires': time() + 15,
+            'user': self.user.pk + 1
+        }))
 
     def test_get_expiration_timestamp(self):
         """get_expiration_timestamp returns greater time than current one"""