changeset 1631:9f02d3c64f48

use ItemCache for page local edit-log, speedup InterWikiMap page handling if page does not exist
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 21 Oct 2006 04:37:50 +0200
parents 9a8fdd5a03d3
children f89736ab2c8e
files MoinMoin/Page.py MoinMoin/wikiutil.py
diffstat 2 files changed, 38 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sat Oct 21 03:13:04 2006 +0200
+++ b/MoinMoin/Page.py	Sat Oct 21 04:37:50 2006 +0200
@@ -419,13 +419,21 @@
     # XXX TODO clean up the mess, rewrite _last_edited, last_edit, lastEditInfo for new logs,
     # XXX TODO do not use mtime() calls any more
     def _last_edited(self, request):
-        from MoinMoin.logfile import editlog
-        try:
-            logfile = editlog.EditLog(request, self.getPagePath('edit-log', check_create=0, isfile=1))
-            logfile.to_end()
-            log = logfile.previous()
-        except StopIteration:
-            log = None
+        # as it is implemented now, this is rather a _last_changed as it just uses
+        # the last log entry, which could be not only from an edit, but also from 
+        # an attachment operation. See different semantics in .mtime().
+        cache_name = self.page_name
+        cache_key = 'lastlog'
+        log = request.cfg.cache.meta.getItem(request, cache_name, cache_key)
+        if log is None:
+            from MoinMoin.logfile import editlog
+            try:
+                logfile = editlog.EditLog(request, rootpage=self.page_name)
+                logfile.to_end()
+                log = logfile.previous()
+            except StopIteration:
+                log = () # don't use None!
+            request.cfg.cache.meta.putItem(request, cache_name, cache_key, log)
         return log
 
     def last_edit(self, request):
@@ -589,22 +597,25 @@
         @rtype: long
         @return: mtime of page (or 0 if page does not exist)
         """
-
-        from MoinMoin.logfile import editlog
-
-        mtime = 0L
-
+        request = self.request
+        cache_name = self.page_name
+        cache_key = 'lastpagechange'
+        mtime = request.cfg.cache.meta.getItem(request, cache_name, cache_key)
         current_wanted = (self.rev == 0) # True if we search for the current revision
-        wanted_rev = "%08d" % self.rev
-
-        try:
-            logfile = editlog.EditLog(self.request, rootpagename=self.page_name)
-            for line in logfile.reverse():
-                if (current_wanted and line.rev != 99999999) or line.rev == wanted_rev:
-                    mtime = line.ed_time_usecs
-                    break
-        except StopIteration:
-            logfile = None
+        if mtime is None or not current_wanted:
+            from MoinMoin.logfile import editlog
+            wanted_rev = "%08d" % self.rev
+            mtime = 0L
+            try:
+                logfile = editlog.EditLog(self.request, rootpagename=self.page_name)
+                for line in logfile.reverse():
+                    if (current_wanted and line.rev != 99999999) or line.rev == wanted_rev:
+                        mtime = line.ed_time_usecs
+                        break
+            except StopIteration:
+                pass
+            if current_wanted:
+                request.cfg.cache.meta.putItem(request, cache_name, cache_key, mtime)
 
         return mtime
 
--- a/MoinMoin/wikiutil.py	Sat Oct 21 03:13:04 2006 +0200
+++ b/MoinMoin/wikiutil.py	Sat Oct 21 04:37:50 2006 +0200
@@ -534,8 +534,11 @@
 def get_max_mtime(file_list, page):
     """ Returns the highest modification time of the files in file_list and the
     page page. """
-    return max([os.stat(filename).st_mtime for filename in file_list] +
-        [version2timestamp(page.mtime_usecs())])
+    timestamps = [os.stat(filename).st_mtime for filename in file_list]
+    if page.exists():
+        # exists() is cached and thus cheaper than mtime_usecs()
+        timestamps.append(version2timestamp(page.mtime_usecs()))
+    return max(timestamps)
 
 
 def load_wikimap(request):