changeset 1266:ff08338e67fe

Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Sun, 13 Aug 2006 13:25:30 +0200
parents b34b3fad8161
children eb9e5e21b0e5
files MoinMoin/action/SyncPages.py MoinMoin/wikisync.py MoinMoin/xmlrpc/__init__.py docs/CHANGES.aschremmer
diffstat 4 files changed, 39 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/SyncPages.py	Sat Aug 12 23:57:39 2006 +0200
+++ b/MoinMoin/action/SyncPages.py	Sun Aug 13 13:25:30 2006 +0200
@@ -81,7 +81,6 @@
         if params["pageList"] is not None:
             params["pageMatch"] = u'|'.join([r'^%s$' % re.escape(name)
                                              for name in params["pageList"]])
-            del params["pageList"]
 
         if params["pageMatch"] is not None:
             params["pageMatch"] = re.compile(params["pageMatch"], re.U)
@@ -89,6 +88,7 @@
         # we do not support matching or listing pages if there is a group of pages
         if params["groupList"]:
             params["pageMatch"] = None
+            params["pageList"] = None
 
         return params
 
@@ -111,9 +111,9 @@
             if not params["remoteWiki"]:
                 raise ActionStatus(_("Incorrect parameters. Please supply at least the ''remoteWiki'' parameter."))
 
-            local = MoinLocalWiki(self.request, params["localPrefix"])
+            local = MoinLocalWiki(self.request, params["localPrefix"], params["pageList"])
             try:
-                remote = MoinRemoteWiki(self.request, params["remoteWiki"], params["remotePrefix"])
+                remote = MoinRemoteWiki(self.request, params["remoteWiki"], params["remotePrefix"], params["pageList"])
             except UnsupportedWikiException, (msg, ):
                 raise ActionStatus(msg)
 
@@ -166,7 +166,7 @@
             print "Processing %r" % rp
 
             local_pagename = rp.local_name
-            current_page = PageEditor(self.request, local_pagename)
+            current_page = PageEditor(self.request, local_pagename) # YYY direct access
             current_rev = current_page.get_real_rev()
 
             tags = TagStore(current_page)
@@ -184,8 +184,7 @@
                 remote_rev = newest_tag.remote_rev
                 if remote_rev == rp.remote_rev and (direction == DOWN or local_rev == current_rev):
                     continue # no changes done, next page
-                old_page = Page(self.request, local_pagename, rev=local_rev)
-                old_contents = old_page.get_raw_body_str()
+                old_contents = Page(self.request, local_pagename, rev=local_rev).get_raw_body_str() # YYY direct access
 
             self.log_status(ActionClass.INFO, _("Synchronising page %(pagename)s with remote page %(remotepagename)s ...") % {"pagename": local_pagename, "remotepagename": rp.remote_name})
 
@@ -232,7 +231,7 @@
 
             # XXX upgrade to write lock
             try:
-                current_page.saveText(verynewtext, current_rev, comment=comment)
+                current_page.saveText(verynewtext, current_rev, comment=comment) # YYY direct access
             except PageEditor.Unchanged:
                 pass
             except PageEditor.EditConflict:
--- a/MoinMoin/wikisync.py	Sat Aug 12 23:57:39 2006 +0200
+++ b/MoinMoin/wikisync.py	Sun Aug 13 13:25:30 2006 +0200
@@ -164,9 +164,10 @@
 
 class MoinRemoteWiki(RemoteWiki):
     """ Used for MoinMoin wikis reachable via XMLRPC. """
-    def __init__(self, request, interwikiname, prefix):
+    def __init__(self, request, interwikiname, prefix, pagelist):
         self.request = request
         self.prefix = prefix
+        self.pagelist = pagelist
         _ = self.request.getText
 
         wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, '%s:""' % (interwikiname, ))
@@ -225,7 +226,8 @@
                    "include_deleted": True,
                    "exclude_non_writable": kwargs["exclude_non_writable"],
                    "include_underlay": False,
-                   "prefix": self.prefix}
+                   "prefix": self.prefix,
+                   "pagelist": self.pagelist}
         pages = self.connection.getAllPagesEx(options)
         rpages = []
         for name, revno in pages:
@@ -241,9 +243,10 @@
 
 class MoinLocalWiki(RemoteWiki):
     """ Used for the current MoinMoin wiki. """
-    def __init__(self, request, prefix):
+    def __init__(self, request, prefix, pagelist):
         self.request = request
         self.prefix = prefix
+        self.pagelist = pagelist
 
     def getGroupItems(self, group_list):
         """ Returns all page names that are listed on the page group_list. """
@@ -269,8 +272,14 @@
 
     def get_pages(self, **kwargs):
         assert not kwargs
-        if self.prefix:
-            page_filter = lambda name,prefix=self.prefix: name.startswith(prefix)
+        if self.prefix or self.pagelist:
+            def page_filter(name, prefix=(self.prefix or ""), pagelist=self.pagelist):
+                n_name = normalise_pagename(name, prefix)
+                if not n_name:
+                    return False
+                if not pagelist:
+                    return True
+                return n_name in pagelist
         else:
             page_filter = lambda x: True
         pages = []
--- a/MoinMoin/xmlrpc/__init__.py	Sat Aug 12 23:57:39 2006 +0200
+++ b/MoinMoin/xmlrpc/__init__.py	Sun Aug 13 13:25:30 2006 +0200
@@ -244,23 +244,33 @@
         @rtype: list
         @return: a list of all pages.
         """
+        from MoinMoin.wikisync import normalise_pagename
         options = {"include_system": True, "include_revno": False, "include_deleted": False,
-                   "exclude_non_writable": False, "include_underlay": True, "prefix": ""}
+                   "exclude_non_writable": False, "include_underlay": True, "prefix": "",
+                   "pagelist": None}
         if opts is not None:
             options.update(opts)
 
         if not options["include_system"]:
-            filter = lambda name: not wikiutil.isSystemPage(self.request, name)
+            p_filter = lambda name: not wikiutil.isSystemPage(self.request, name)
         else:
-            filter = lambda name: True
+            p_filter = lambda name: True
 
         if options["exclude_non_writable"]:
-            filter = lambda name, filter=filter: filter(name) and self.request.user.may.write(name)
+            p_filter = lambda name, p_filter=p_filter: p_filter(name) and self.request.user.may.write(name)
 
-        if options["prefix"]:
-            filter = lambda name, filter=filter, prefix=options["prefix"]: filter(name) and name.startswith(prefix)
+        if options["prefix"] or options["pagelist"]:
+            def p_filter(name, p_filter=p_filter, prefix=(options["prefix"] or ""), pagelist=options["pagelist"]):
+                if not p_filter(name):
+                    return False
+                n_name = normalise_pagename(name, prefix)
+                if not n_name:
+                    return False
+                if not pagelist:
+                    return True
+                return n_name in pagelist
 
-        pagelist = self.request.rootpage.getPageList(filter=filter, exists=not options["include_deleted"],
+        pagelist = self.request.rootpage.getPageList(filter=p_filter, exists=not options["include_deleted"],
                                                      include_underlay=options["include_underlay"])
         
         if options['include_revno']:
--- a/docs/CHANGES.aschremmer	Sat Aug 12 23:57:39 2006 +0200
+++ b/docs/CHANGES.aschremmer	Sun Aug 13 13:25:30 2006 +0200
@@ -17,6 +17,7 @@
     * Add page locking, i.e. use the one in the new storage layer.
     * Check what needs to be documented on MoinMaster.
     * Search for XXX
+    * Maybe refactor YYY into MoinLocalWiki
     * Put author names into the comment field, transmit mimetypes.
 
   New Features:
@@ -98,7 +99,7 @@
          XMLRPC functions to return Fault instances. Introduced a new diff3 mode that should reduce the
          conflicts. Fixed hard to track down bugs in SyncPages. Store full IWIDs and match by
          either of both components when searching for tags. Ignore underlay pages. Filter the remote page list by
-         the prefix on the remote side.
+         the prefix and the pageList on the remote side.
 
 2006-07-18: the requested daily entry is missing here, see http://moinmoin.wikiwikiweb.de/GoogleSoc2006/BetterProgress
 2006-07-19: the requested daily entry is missing here, see http://moinmoin.wikiwikiweb.de/GoogleSoc2006/BetterProgress