changeset 6025:05a6897ee496

"userdir" caching scope: use it for userid lookup caches, reduce code duplication For same reasons (see previous changesets), we need to use the "userdir" scope for the name2id / openid2id lookup caches, too.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 12 Feb 2014 12:07:22 +0100
parents ad461ba29a17
children 28a3951fc9f6
files MoinMoin/_tests/__init__.py MoinMoin/_tests/test_user.py MoinMoin/script/maint/cleancache.py MoinMoin/user.py docs/CHANGES
diffstat 5 files changed, 20 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/__init__.py	Wed Feb 12 01:15:00 2014 +0100
+++ b/MoinMoin/_tests/__init__.py	Wed Feb 12 12:07:22 2014 +0100
@@ -60,10 +60,7 @@
     # really get rid of the user
     fpath = os.path.join(user_dir, user_id)
     os.remove(fpath)
-    # delete cache
-    arena = 'user'
-    key = 'name2id'
-    caching.CacheEntry(request, arena, key, scope='wiki').remove()
+    user.clearUserIdLookupCaches(request)
 
 # Creating and destroying test pages --------------------------------
 
--- a/MoinMoin/_tests/test_user.py	Wed Feb 12 01:15:00 2014 +0100
+++ b/MoinMoin/_tests/test_user.py	Wed Feb 12 12:07:22 2014 +0100
@@ -77,12 +77,8 @@
         self.request.cookies = self.saved_cookie
         self.request.user = self.saved_user
 
-        # Remove user name to id cache, or next test will fail
-        caching.CacheEntry(self.request, 'user', 'name2id', scope='wiki').remove()
-        try:
-            del self.request.cfg.cache.name2id
-        except:
-            pass
+        # Remove user lookup caches, or next test will fail
+        user.clearUserIdLookupCaches(self.request)
 
     def testAsciiPassword(self):
         """ user: login with ascii password """
--- a/MoinMoin/script/maint/cleancache.py	Wed Feb 12 01:15:00 2014 +0100
+++ b/MoinMoin/script/maint/cleancache.py	Wed Feb 12 12:07:22 2014 +0100
@@ -55,7 +55,6 @@
             ('charts', 'hitcounts'),
             ('charts', 'pagehits'),
             ('charts', 'useragents'),
-            ('user', 'name2id'),
         ]
         for arena, key in arena_key_list:
             caching.CacheEntry(request, arena, key, scope='wiki').remove()
--- a/MoinMoin/user.py	Wed Feb 12 01:15:00 2014 +0100
+++ b/MoinMoin/user.py	Wed Feb 12 12:07:22 2014 +0100
@@ -82,12 +82,11 @@
     if not search or not key:
         return None
     cfg = request.cfg
-    cachekey = '%s2id' % key
+    scope, arena, cachekey = 'userdir', 'users', '%s2id' % key
     try:
         _key2id = getattr(cfg.cache, cachekey)
     except AttributeError:
-        arena = 'user'
-        cache = caching.CacheEntry(request, arena, cachekey, scope='wiki', use_pickle=True)
+        cache = caching.CacheEntry(request, arena, cachekey, scope=scope, use_pickle=True)
         try:
             _key2id = cache.content()
         except caching.CacheError:
@@ -104,8 +103,7 @@
                         _key2id[val] = userid
                 else:
                     _key2id[value] = userid
-        arena = 'user'
-        cache = caching.CacheEntry(request, arena, cachekey, scope='wiki', use_pickle=True)
+        cache = caching.CacheEntry(request, arena, cachekey, scope=scope, use_pickle=True)
         try:
             cache.update(_key2id)
         except caching.CacheError:
@@ -114,6 +112,16 @@
     return uid
 
 
+def clearUserIdLookupCaches(request):
+    scope, arena = 'userdir', 'users'
+    for key in ['name2id', 'openid2id', ]:
+        caching.CacheEntry(request, arena, key, scope=scope).remove()
+        try:
+            delattr(request.cfg.cache, key)
+        except:
+            pass
+
+
 def getUserId(request, searchName):
     """ Get the user ID for a specific user NAME.
 
@@ -686,19 +694,7 @@
             data.write(line + '\n')
         data.close()
 
-        arena = 'user'
-        key = 'name2id'
-        caching.CacheEntry(self._request, arena, key, scope='wiki').remove()
-        try:
-            del self._request.cfg.cache.name2id
-        except:
-            pass
-        key = 'openid2id'
-        caching.CacheEntry(self._request, arena, key, scope='wiki').remove()
-        try:
-            del self._request.cfg.cache.openid2id
-        except:
-            pass
+        clearUserIdLookupCaches(self._request)
 
         if not self.disabled:
             self.valid = 1
--- a/docs/CHANGES	Wed Feb 12 01:15:00 2014 +0100
+++ b/docs/CHANGES	Wed Feb 12 12:07:22 2014 +0100
@@ -91,6 +91,9 @@
   * fix crash when macro names contain non-ascii chars
   * CopyPage action: fix NameError exception when TextCha was answered wrong
   * docbook formatter: fix image URL generation, avoid script name duplication
+  * fix caching scope of name2id/openid2id caches (was: "wiki", now:
+    "userdir"). this is relevant for shared user_dir configurations.
+  * moin maint cleancache: cleans up openid2id cache now also
 
   Other changes:
   * rss_rc action (RSS feed) is now much faster / much less resource consuming