changeset 1679:d6b93908e4d9

save CPU and disk I/O by checking for spiders in LikePages and EditTemplates macro, both used on MissingPage (ported from 1.5)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 19 Nov 2006 17:30:59 +0100
parents 20f3ec17cf9f
children eee86327fe92
files MoinMoin/macro/EditTemplates.py MoinMoin/macro/LikePages.py docs/CHANGES
diffstat 3 files changed, 34 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/macro/EditTemplates.py	Sun Nov 19 16:46:38 2006 +0100
+++ b/MoinMoin/macro/EditTemplates.py	Sun Nov 19 17:30:59 2006 +0100
@@ -12,19 +12,23 @@
 from MoinMoin import wikiutil
 
 def execute(self, args):
-    # Get list of template pages readable by current user
-    filter = self.request.cfg.cache.page_template_regex.search
-    templates = self.request.rootpage.getPageList(filter=filter)
-    result = []
-    if templates:
-        templates.sort()
-        page = self.formatter.page
-        # send list of template pages
-        result.append(self.formatter.bullet_list(1))
-        for template in templates:
-            result.append(self.formatter.listitem(1))
-            result.append(page.link_to(self.request, template, querystr={'action': 'edit', 'template': template}))
-            result.append(self.formatter.listitem(0))
-        result.append(self.formatter.bullet_list(0))
-    return ''.join(result)
+    result = ''
+    # we don't want to spend much CPU for spiders requesting nonexisting pages
+    if not self.request.isSpiderAgent:
+        # Get list of template pages readable by current user
+        filter = self.request.cfg.cache.page_template_regex.search
+        templates = self.request.rootpage.getPageList(filter=filter)
+        result = []
+        if templates:
+            templates.sort()
+            page = self.formatter.page
+            # send list of template pages
+            result.append(self.formatter.bullet_list(1))
+            for template in templates:
+                result.append(self.formatter.listitem(1))
+                result.append(page.link_to(self.request, template, querystr={'action': 'edit', 'template': template}))
+                result.append(self.formatter.listitem(0))
+            result.append(self.formatter.bullet_list(0))
+        result = ''.join(result)
+    return result
 
--- a/MoinMoin/macro/LikePages.py	Sun Nov 19 16:46:38 2006 +0100
+++ b/MoinMoin/macro/LikePages.py	Sun Nov 19 17:30:59 2006 +0100
@@ -12,14 +12,17 @@
 
 def execute(macro, args):
     request = macro.request
-    pagename = macro.formatter.page.page_name
-
-    # Get matches
-    start, end, matches = LikePages.findMatches(pagename, request)
+    # we don't want to spend much CPU for spiders requesting nonexisting pages
+    if not request.isSpiderAgent:
+        pagename = macro.formatter.page.page_name
 
-    # Render matches
-    if matches and not isinstance(matches, (str, unicode)):
-        return request.redirectedOutput(LikePages.showMatches, pagename, request, start, end, matches, False)
+        # Get matches
+        start, end, matches = LikePages.findMatches(pagename, request)
 
-    return args
+        # Render matches
+        if matches and not isinstance(matches, (str, unicode)):
+            return request.redirectedOutput(LikePages.showMatches, pagename, request, start, end, matches, False)
 
+        return args
+    return ''
+
--- a/docs/CHANGES	Sun Nov 19 16:46:38 2006 +0100
+++ b/docs/CHANGES	Sun Nov 19 17:30:59 2006 +0100
@@ -399,6 +399,10 @@
       url_prefix can be a remote server serving the static files (css/img).
       If not set (or set to None), url_prefix_local will default to the value
       of url_prefix.
+    * We save some CPU and disk I/O by having EditTemplates and LikePages macro
+      (both used on MissingPage) check whether the requesting entity was
+      identified as a spider (e.g. search engine bot) and do nothing in that
+      case. Normal users won't see any difference.
 
 Version 1.5.6:
   A general security notice: