Commits

Ivan Melnikov  committed addeb18 Draft

Cache user authorization

  • Participants
  • Parent commits 93065f1

Comments (0)

Files changed (1)

 
 CACHE_USER = 'user:'
 CACHE_USER_ID = 'user_id:'
+CACHE_AUTH = 'auth:'
 
 def get_user(user_id=None):
 	if user_id:
 			return
 
 		# Check user has been approved
-		one = User.all().filter('user_id', user.user_id()).filter('approved !=', None).fetch(1)
-		if not one:
-			self.redirect('/_docs/join.html')
-			return
+		key = CACHE_AUTH+user.user_id()
+		grant = memcache.get(key)
+		if grant is None:
+			one = User.all().filter('user_id', user.user_id()).filter('approved !=', None).fetch(1)
+			if not one:
+				grant = False
+				self.redirect('/_docs/join.html')
+				return
+			else:
+				grant = True
+		memcache.set(key, grant)
 
 		# execute method
 		return target(self, *args, **kwargs)