Attachment 'patch-cache-pageparams-1.9.diff'

Download

   1 diff -r 5738b78f53b5 MoinMoin/Page.py
   2 --- a/MoinMoin/Page.py	Sat Nov 30 20:09:43 2013 +0100
   3 +++ b/MoinMoin/Page.py	Sat Mar 29 16:23:44 2014 +0100
   4 @@ -41,6 +41,7 @@
   5  
   6  from MoinMoin import config, caching, user, util, wikiutil
   7  from MoinMoin.logfile import eventlog
   8 +from MoinMoin.support.python_compatibility import hash_new
   9  
  10  def is_cache_exception(e):
  11      args = e.args
  12 @@ -1254,15 +1255,17 @@
  13              request.formatter = old_formatter
  14  
  15  
  16 -    def getFormatterName(self):
  17 +    def getFormatterName(self, request=None):
  18          """ Return a formatter name as used in the caching system
  19  
  20 +        @param request: the active request (optional)
  21          @rtype: string
  22          @return: formatter name as used in caching
  23          """
  24 -        if not hasattr(self, 'formatter') or self.formatter is None:
  25 +        formatter = getattr(self, 'formatter', None) or request and getattr(request, 'formatter', None)
  26 +        if not formatter:
  27              return ''
  28 -        module = self.formatter.__module__
  29 +        module = formatter.__module__
  30          return module[module.rfind('.') + 1:]
  31  
  32      def canUseCache(self, parser=None):
  33 @@ -1351,9 +1354,12 @@
  34  
  35      def loadCache(self, request):
  36          """ Return page content cache or raises 'CacheNeedsUpdate' """
  37 -        cache = caching.CacheEntry(request, self, self.getFormatterName(), scope='item')
  38 -        attachmentsPath = self.getPagePath('attachments', check_create=0)
  39 -        if cache.needsUpdate(self._text_filename(), attachmentsPath):
  40 +        for with_params in (True, False):
  41 +            cache = caching.CacheEntry(request, self, self.getCacheKey(request, with_params), scope='item')
  42 +            attachmentsPath = self.getPagePath('attachments', check_create=0)
  43 +            if not cache.needsUpdate(self._text_filename(), attachmentsPath):
  44 +                break
  45 +        else:
  46              raise Exception('CacheNeedsUpdate')
  47  
  48          import marshal
  49 @@ -1372,7 +1378,7 @@
  50          """ Format content into code, update cache and return code """
  51          import marshal
  52          from MoinMoin.formatter.text_python import Formatter
  53 -        formatter = Formatter(request, ["page"], self.formatter)
  54 +        formatter = Formatter(request, ["page", "pageparams"], self.formatter)
  55  
  56          # Save request state while formatting page
  57          saved_current_lang = request.current_lang
  58 @@ -1384,10 +1390,44 @@
  59          src = formatter.assemble_code(text)
  60          code = compile(src.encode(config.charset),
  61                         self.page_name.encode(config.charset), 'exec')
  62 -        cache = caching.CacheEntry(request, self, self.getFormatterName(), scope='item')
  63 +        self.enforceCacheLimit(request)
  64 +        # Determine whether the parameters/args need to be incorporated into the
  65 +        # cache entry key.
  66 +        with_params = "pageparams" in formatter.getReportedDependencies()
  67 +        cache = caching.CacheEntry(request, self, self.getCacheKey(request, with_params), scope='item')
  68          cache.update(marshal.dumps(code))
  69          return code
  70  
  71 +    def enforceCacheLimit(self, request):
  72 +        """ Prevent too many cache entries being stored for a page """
  73 +        keys = caching.get_cache_list(request, self, 'item')
  74 +        try:
  75 +            cache_limit = int(getattr(request.cfg, 'page_cache_limit', "10"))
  76 +        except ValueError:
  77 +            cache_limit = 10
  78 +
  79 +        if len(keys) >= cache_limit:
  80 +            items = [caching.CacheEntry(request, self, key, scope='item') for key in keys]
  81 +            item_ages = [(item.mtime(), item) for item in items]
  82 +            item_ages.sort()
  83 +            for item_age, item in item_ages[:-cache_limit]:
  84 +                item.remove()
  85 +
  86 +    def getCacheKey(self, request, with_params=False, key=None):
  87 +        """ Generate a cache key for a page using optional request information """
  88 +        key = key or self.getFormatterName(request)
  89 +        if with_params and request.args:
  90 +            args = request.args.items(True)
  91 +            args.sort()
  92 +            key_args = []
  93 +            for k, v in args:
  94 +                if not (k == "action" and v == "refresh"):
  95 +                    key_args.append("%s=%s" % (k, wikiutil.url_quote(v)))
  96 +            arg_str = "&".join(key_args)
  97 +            if arg_str:
  98 +                key = "%s:%s" % (key, hash_new('sha1', arg_str).hexdigest())
  99 +        return key
 100 +
 101      def _specialPageText(self, request, special_type):
 102          """ Output the default page content for new pages.
 103  
 104 diff -r 5738b78f53b5 MoinMoin/action/refresh.py
 105 --- a/MoinMoin/action/refresh.py	Sat Nov 30 20:09:43 2013 +0100
 106 +++ b/MoinMoin/action/refresh.py	Sat Mar 29 16:23:44 2014 +0100
 107 @@ -14,11 +14,14 @@
 108      arena = request.values.get('arena', 'Page.py')
 109      if arena == 'Page.py':
 110          arena = Page(request, pagename)
 111 -    key = request.values.get('key', 'text_html')
 112 +    prefix = request.values.get('key', 'text_html')
 113  
 114      # Remove cache entry (if exists), and send the page
 115      from MoinMoin import caching
 116 -    caching.CacheEntry(request, arena, key, scope='item').remove()
 117 +    keys = caching.get_cache_list(request, arena, 'item')
 118 +    for key in keys:
 119 +        if key.startswith(prefix):
 120 +            caching.CacheEntry(request, arena, key, scope='item').remove()
 121      caching.CacheEntry(request, arena, "pagelinks", scope='item').remove()
 122      request.page.send_page()
 123  
 124 diff -r 5738b78f53b5 MoinMoin/formatter/text_python.py
 125 --- a/MoinMoin/formatter/text_python.py	Sat Nov 30 20:09:43 2013 +0100
 126 +++ b/MoinMoin/formatter/text_python.py	Sat Mar 29 16:23:44 2014 +0100
 127 @@ -10,6 +10,7 @@
 128  
 129  import time
 130  from MoinMoin import wikiutil
 131 +from MoinMoin.support.python_compatibility import set
 132  
 133  
 134  class Formatter:
 135 @@ -40,6 +41,12 @@
 136          self.text_cmd_begin = '\nrequest.write('
 137          self.text_cmd_end = ')\n'
 138  
 139 +        # Record dependency requirements of certain content
 140 +        self.__dependencies = set()
 141 +
 142 +    def getReportedDependencies(self):
 143 +        return self.__dependencies
 144 +
 145      def assemble_code(self, text):
 146          """inserts the code into the generated text
 147          """
 148 @@ -186,7 +193,10 @@
 149              return self.formatter.div(on, **kw)
 150  
 151      def macro(self, macro_obj, name, args, markup=None):
 152 -        if self.__is_static(macro_obj.get_dependencies(name)):
 153 +        Dependencies = macro_obj.get_dependencies(name)
 154 +        self.__dependencies.update(Dependencies)
 155 +
 156 +        if self.__is_static(Dependencies):
 157              # XXX: why is this necessary??
 158              macro_obj.formatter = self
 159              return macro_obj.execute(name, args)
 160 @@ -204,6 +214,7 @@
 161              Dependencies = wikiutil.searchAndImportPlugin(self.request.cfg, "parser", parser_name, "Dependencies")
 162          except (wikiutil.PluginMissingError, wikiutil.PluginAttributeError):
 163              Dependencies = self.defaultDependencies
 164 +        self.__dependencies.update(Dependencies)
 165  
 166          if self.__is_static(Dependencies):
 167              return self.formatter.parser(parser_name, lines)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2011-07-11 21:50:51, 29.7 KB) [[attachment:2011-07-11-EventAggregator-calendar-view.png]]
  • [get | view] (2011-07-11 21:51:03, 23.9 KB) [[attachment:2011-07-11-EventAggregator-day-view.png]]
  • [get | view] (2011-07-11 21:51:14, 86.4 KB) [[attachment:2011-07-11-EventAggregator-map-view.png]]
  • [get | view] (2009-04-01 23:20:48, 23.3 KB) [[attachment:EventAggregator-0.1.tar.gz]]
  • [get | view] (2013-05-06 17:34:34, 232.2 KB) [[attachment:EventAggregator-0.10.1.tar.bz2]]
  • [get | view] (2013-10-30 14:52:25, 233.6 KB) [[attachment:EventAggregator-0.10.2.tar.bz2]]
  • [get | view] (2013-05-05 18:40:11, 238.5 KB) [[attachment:EventAggregator-0.10.tar.bz2]]
  • [get | view] (2009-04-04 21:48:28, 25.7 KB) [[attachment:EventAggregator-0.2.tar.gz]]
  • [get | view] (2009-06-08 21:54:39, 29.7 KB) [[attachment:EventAggregator-0.3.tar.gz]]
  • [get | view] (2009-11-08 19:04:45, 33.1 KB) [[attachment:EventAggregator-0.4.tar.gz]]
  • [get | view] (2010-02-16 23:34:21, 36.0 KB) [[attachment:EventAggregator-0.5.tar.gz]]
  • [get | view] (2011-02-06 01:53:31, 38.9 KB) [[attachment:EventAggregator-0.6.1.tar.gz]]
  • [get | view] (2011-04-05 22:37:14, 48.4 KB) [[attachment:EventAggregator-0.6.2.tar.gz]]
  • [get | view] (2011-04-05 22:36:57, 48.6 KB) [[attachment:EventAggregator-0.6.3.tar.gz]]
  • [get | view] (2011-04-05 22:36:13, 48.8 KB) [[attachment:EventAggregator-0.6.4.tar.gz]]
  • [get | view] (2010-04-12 18:35:59, 45.7 KB) [[attachment:EventAggregator-0.6.tar.gz]]
  • [get | view] (2011-08-09 23:03:55, 229.0 KB) [[attachment:EventAggregator-0.7.1.tar.gz]]
  • [get | view] (2011-07-11 22:06:50, 228.9 KB) [[attachment:EventAggregator-0.7.tar.gz]]
  • [get | view] (2011-11-11 23:55:04, 231.2 KB) [[attachment:EventAggregator-0.8.1.tar.bz2]]
  • [get | view] (2012-02-14 23:30:04, 232.1 KB) [[attachment:EventAggregator-0.8.2.tar.bz2]]
  • [get | view] (2012-02-14 23:30:19, 232.2 KB) [[attachment:EventAggregator-0.8.3.tar.bz2]]
  • [get | view] (2012-03-25 22:46:32, 232.2 KB) [[attachment:EventAggregator-0.8.4.tar.bz2]]
  • [get | view] (2012-09-11 20:58:21, 232.5 KB) [[attachment:EventAggregator-0.8.5.tar.bz2]]
  • [get | view] (2011-10-09 23:32:49, 230.8 KB) [[attachment:EventAggregator-0.8.tar.bz2]]
  • [get | view] (2013-02-04 23:20:17, 230.8 KB) [[attachment:EventAggregator-0.9.tar.bz2]]
  • [get | view] (2009-04-01 23:20:18, 21.7 KB) [[attachment:EventAggregator.png]]
  • [get | view] (2009-04-04 21:49:00, 35.8 KB) [[attachment:EventAggregator1.png]]
  • [get | view] (2014-03-29 15:08:46, 6.9 KB) [[attachment:patch-cache-pageparams-1.8.diff]]
  • [get | view] (2014-03-29 15:08:31, 6.8 KB) [[attachment:patch-cache-pageparams-1.9.diff]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.