changeset 1646:2fbb179f3518

use filepos in (not mtime of) edit-log for editlog.news, fix some bugs in logfile
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 31 Oct 2006 12:22:38 +0100
parents e17071207c4a
children c0cb0884f7ec
files MoinMoin/Page.py MoinMoin/logfile/__init__.py MoinMoin/logfile/editlog.py
diffstat 3 files changed, 27 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sun Oct 29 22:38:12 2006 +0100
+++ b/MoinMoin/Page.py	Tue Oct 31 12:22:38 2006 +0100
@@ -33,7 +33,7 @@
         """
         self.name = name
         self.cache = {}
-        self.timestamp = None
+        self.log_pos = None
         self.requests = 0
         self.hits = 0
 
@@ -80,7 +80,7 @@
         """
         from MoinMoin.logfile import editlog
         elog = editlog.EditLog(request)
-        self.timestamp, items = elog.news(self.timestamp)
+        self.log_pos, items = elog.news(self.log_pos)
         if items:
             if self.name == 'meta':
                 for item in items:
--- a/MoinMoin/logfile/__init__.py	Sun Oct 29 22:38:12 2006 +0100
+++ b/MoinMoin/logfile/__init__.py	Tue Oct 31 12:22:38 2006 +0100
@@ -2,7 +2,7 @@
 """
     MoinMoin - LogFile package
 
-    @copyright: 2005 by Thomas Waldmann (MoinMoin:ThomasWaldmann)
+    @copyright: 2005-2006 by Thomas Waldmann (MoinMoin:ThomasWaldmann)
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -52,7 +52,9 @@
         self.len = len(self.lines)
 
     def __calculate_offsets(self, offset):
-        """
+        """ Calculate the file offsets of all read lines and also the offset of
+            the position after the last read line (stored into self.offsets[-1])
+        
         @param offset: offset of the first line
         """
         self.offsets = map(lambda x:len(x), self.lines)
@@ -207,7 +209,7 @@
         """
         self.__rel_index = self.__rel_index + lines
         while self.__rel_index < 0:
-            if self.__buffer == self.__buffer2:
+            if self.__buffer is self.__buffer2:
                 # change to buffer 1
                 self.__buffer = self.__buffer1
                 self.__rel_index = self.__rel_index + self.__buffer.len
@@ -230,7 +232,7 @@
                     self.__buffer = self.__buffer1
 
         while self.__rel_index >= self.__buffer.len:
-            if self.__buffer == self.__buffer1:
+            if self.__buffer is self.__buffer1:
                 # change to buffer 2
                 self.__rel_index = self.__rel_index - self.__buffer.len
                 self.__buffer = self.__buffer2
@@ -245,7 +247,8 @@
                         self.__lineno = (self.__lineno + lines -
                                          (self.__rel_index -
                                           len(self.__buffer.offsets)))
-                    self.__rel_index = len(self.__buffer.offsets)
+                    self.__rel_index = self.__buffer.len # point to after last read line
+                    # was (wrong): ... = len(self.__buffer.offsets)
                     return True
                 # shift buffers
                 self.__buffer1 = self.__buffer2
@@ -340,12 +343,11 @@
         .seek is much more efficient for moving long distances than .peek.
         raises ValueError if position is invalid
         """
-        if self.__buffer1.offsets[0] <= position < self.__buffer1.offsets[-1]:
+        if self.__buffer1 and self.__buffer1.offsets[0] <= position < self.__buffer1.offsets[-1]:
             # position is in .__buffer1 
             self.__rel_index = self.__buffer1.offsets.index(position)
             self.__buffer = self.__buffer1
-        elif (self.__buffer2.offsets[0] <= position <
-              self.__buffer2.offsets[-1]):
+        elif self.__buffer2 and self.__buffer2.offsets[0] <= position < self.__buffer2.offsets[-1]:
             # position is in .__buffer2
             self.__rel_index = self.__buffer2.offsets.index(position)
             self.__buffer = self.__buffer2
--- a/MoinMoin/logfile/editlog.py	Sun Oct 29 22:38:12 2006 +0100
+++ b/MoinMoin/logfile/editlog.py	Tue Oct 31 12:22:38 2006 +0100
@@ -4,7 +4,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import os.path
+import os.path, logging
 from MoinMoin.logfile import LogFile
 from MoinMoin import wikiutil, user, config
 from MoinMoin.Page import Page
@@ -208,16 +208,20 @@
         self.filter = eval("lambda x: " + expr)
 
 
-    def news(self, oldtimestamp):
-        """ What has changed in the edit-log since <timestamp>?
-            Returns edit-log timestamp and list of changed item names.
+    def news(self, oldposition):
+        """ What has changed in the edit-log since <oldposition>?
+            Returns edit-log final position() and list of changed item names.
         """
-        newtimestamp = self.date()
+        if oldposition is None:
+            self.to_end()
+        else:
+            self.seek(oldposition)
         items = []
-        if oldtimestamp is not None and oldtimestamp != newtimestamp:
-            for line in self.reverse():
-                if line.ed_time_usecs <= oldtimestamp:
-                    break
-                items.append(line.pagename)
-        return newtimestamp, items
+        for line in self:
+            items.append(line.pagename)
 
+        newposition = self.position()
+        logging.debug("editlog.news: new pos: %r new items: %r", newposition, items)
+        # FIXME if 1 item is changed, items is [oneitem, oneitem, oneitem]!
+        return newposition, items
+