changeset 902:6cc24670fd0f

Speeded up linkto: search by avoiding read locks on pagelinks retrieval.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Thu, 06 Jul 2006 23:24:08 +0200
parents f719f5c0bd4e
children 14c71dafc9dd
files MoinMoin/Page.py MoinMoin/caching.py docs/CHANGES
diffstat 3 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Thu Jul 06 20:40:56 2006 +0200
+++ b/MoinMoin/Page.py	Thu Jul 06 23:24:08 2006 +0200
@@ -1535,7 +1535,7 @@
         """
         if not self.exists():
             return []
-        cache = caching.CacheEntry(request, self, 'pagelinks', scope='item')
+        cache = caching.CacheEntry(request, self, 'pagelinks', scope='item', do_locking=False)
         if cache.needsUpdate(self._text_filename()):
             links = self.parsePageLinks(request)
             cache.update('\n'.join(links) + '\n', True)
--- a/MoinMoin/caching.py	Thu Jul 06 20:40:56 2006 +0200
+++ b/MoinMoin/caching.py	Thu Jul 06 23:24:08 2006 +0200
@@ -15,12 +15,13 @@
     from MoinMoin.util import lock
     
 class CacheEntry:
-    def __init__(self, request, arena, key, scope='page_or_wiki'):
+    def __init__(self, request, arena, key, scope='page_or_wiki', do_locking=True):
         """ init a cache entry
             @param request: the request object
             @param arena: either a string or a page object, when we want to use
                           page local cache area
             @param key: under which key we access the cache content
+            @param lock: if there should be a lock, normally True
             @param scope: the scope where we are caching:
                           'item' - an item local cache
                           'wiki' - a wiki local cache
@@ -43,7 +44,8 @@
             self.arena_dir = os.path.join(request.cfg.cache_dir, '__common__', arena)
             filesys.makeDirs(self.arena_dir)
         self.key = key
-        if locking:
+        self.locking = do_locking and locking
+        if self.locking:
             self.lock_dir = os.path.join(self.arena_dir, '__lock__')
             self.rlock = lock.ReadLock(self.lock_dir, 60.0)
             self.wlock = lock.WriteLock(self.lock_dir, 60.0)
@@ -84,7 +86,7 @@
 
     def copyto(self, filename):
         import shutil
-        if not locking or locking and self.wlock.acquire(1.0):
+        if not self.locking or self.locking and self.wlock.acquire(1.0):
             try:
                 shutil.copyfile(filename, self._filename())
                 try:
@@ -92,7 +94,7 @@
                 except OSError:
                     pass
             finally:
-                if locking:
+                if self.locking:
                     self.wlock.release()
         else:
             self.request.log("Can't acquire write lock in %s" % self.lock_dir)
@@ -100,7 +102,7 @@
     def update(self, content, encode=False):
         if encode:
             content = content.encode(config.charset)
-        if not locking or locking and self.wlock.acquire(1.0):
+        if not self.locking or self.locking and self.wlock.acquire(1.0):
             try:
                 f = open(self._filename(), 'wb')
                 f.write(content)
@@ -110,7 +112,7 @@
                 except OSError:
                     pass
             finally:
-                if locking:
+                if self.locking:
                     self.wlock.release()
         else:
             self.request.log("Can't acquire write lock in %s" % self.lock_dir)
@@ -122,13 +124,13 @@
             pass
 
     def content(self, decode=False):
-        if not locking or locking and self.rlock.acquire(1.0):
+        if not self.locking or self.locking and self.rlock.acquire(1.0):
             try:
                 f = open(self._filename(), 'rb')
                 data = f.read()
                 f.close()
             finally:
-                if locking:
+                if self.locking:
                     self.rlock.release()
         else:
             self.request.log("Can't acquire read lock in %s" % self.lock_dir)
--- a/docs/CHANGES	Thu Jul 06 20:40:56 2006 +0200
+++ b/docs/CHANGES	Thu Jul 06 23:24:08 2006 +0200
@@ -158,6 +158,7 @@
     * Included EmbedObject macro for embedding shockwave flash, mp3, visio, ...
     * @SIG@ etc. generate local time stamps now, no difference visible on page
       view.
+    * Speeded up linkto search by avoiding read locks on the pagelinks file.
 
   Bugfixes:
     * on action "info" page, "revert" link will not be displayed for empty page