changeset 6030:5ab38cec99f7

only cache valid user's attributes (we don't care for invalid/disabled user profiles)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 14 Feb 2014 15:29:47 +0100
parents e2da1c1183d8
children 1b2e1497f5ed
files MoinMoin/user.py
diffstat 1 files changed, 28 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/user.py	Fri Feb 14 14:59:29 2014 +0100
+++ b/MoinMoin/user.py	Fri Feb 14 15:29:47 2014 +0100
@@ -165,15 +165,16 @@
         cache[attrname] = {}
     for userid in getUserList(request):
         u = User(request, id=userid)
-        for attrname in CACHED_USER_ATTRS:
-            if hasattr(u, attrname):
-                attr2id = cache[attrname]
-                value = getattr(u, attrname)
-                if isinstance(value, list):
-                    for val in value:
-                        attr2id[val] = userid
-                else:
-                    attr2id[value] = userid
+        if u.valid:
+            for attrname in CACHED_USER_ATTRS:
+                if hasattr(u, attrname):
+                    attr2id = cache[attrname]
+                    value = getattr(u, attrname)
+                    if isinstance(value, list):
+                        for val in value:
+                            attr2id[val] = userid
+                    else:
+                        attr2id[value] = userid
 
     setMemoryLookupCaches(request, cache)
     diskcache.update(cache)
@@ -771,11 +772,11 @@
             data.write(line + '\n')
         data.close()
 
-        self.updateLookupCaches()
-
         if not self.disabled:
             self.valid = 1
 
+        self.updateLookupCaches()
+
         if not self._stored:
             self._stored = True
             event = events.UserCreatedEvent(self._request, self)
@@ -980,8 +981,8 @@
         cache.lock('w')
         page_sub = cache.content()
 
-        # we don't care about storing entries for users without any page subscriptions
-        if self.subscribed_pages:
+        # we only store entries for valid users with some page subscriptions
+        if self.valid and self.subscribed_pages:
             page_sub[self.id] = {
                 'name': self.name,
                 'email': self.email,
@@ -1014,19 +1015,20 @@
                     print "deleting old cached attr %s -> %s" % (key, value)
                     del attr2id[key]
 
-        # then update with the current attr values:
-        for attrname in CACHED_USER_ATTRS:
-            if hasattr(self, attrname):
-                value = getattr(self, attrname)
-                if value:
-                    # we do not store empty values, likely not unique
-                    print "setting new cached attr %s -> %r" % (attrname, value)
-                    attr2id = cache[attrname]
-                    if isinstance(value, list):
-                        for val in value:
-                            attr2id[val] = userid
-                    else:
-                        attr2id[value] = userid
+        # then, if user is valid, update with the current attr values:
+        if self.valid:
+            for attrname in CACHED_USER_ATTRS:
+                if hasattr(self, attrname):
+                    value = getattr(self, attrname)
+                    if value:
+                        # we do not store empty values, likely not unique
+                        print "setting new cached attr %s -> %r" % (attrname, value)
+                        attr2id = cache[attrname]
+                        if isinstance(value, list):
+                            for val in value:
+                                attr2id[val] = userid
+                        else:
+                            attr2id[value] = userid
 
         setMemoryLookupCaches(self._request, cache)
         diskcache.update(cache)