Attachment '2.patch'
Download 1 changeset: 4207:0009178b69ef
2 branch: docbook
3 tag: tip
4 user: matthijs@stdin.nl
5 date: Wed Dec 03 10:39:22 2008 +0100
6 summary: docbook parser: Use only a single cache entry.
7
8 diff -r 0274b9f1343b -r 0009178b69ef MoinMoin/parser/text_docbook.py
9 --- a/MoinMoin/parser/text_docbook.py Mon Nov 24 22:40:14 2008 +0100
10 +++ b/MoinMoin/parser/text_docbook.py Wed Dec 03 10:39:22 2008 +0100
11 @@ -67,24 +67,17 @@
12 # speed up rendering. We have a separate entry for the filename,
13 # so we can properly refresh the cache when the docbook_xsl
14 # configuration value changes.
15 - self.cached = caching.CacheEntry(self.request,
16 - arena='docbook',
17 - key='compiled_xsl',
18 - scope='farm',
19 - use_pickle=True)
20 -
21 - self.cached_name = caching.CacheEntry(self.request,
22 - arena='docbook',
23 - key='docbook_xsl_filename',
24 - scope='farm',
25 - use_pickle=True)
26 -
27 + self.cached_xsl = caching.CacheEntry(self.request,
28 + arena='docbook',
29 + key='compiled_xsl',
30 + scope='farm',
31 + use_pickle=True)
32
33 def format(self, formatter):
34 self.wikiParser.formatter = formatter
35 XsltParser.format(self, formatter)
36
37 - def get_cached_stylesheet(self, abs_db_xsl, log=True):
38 + def get_cached_stylesheet(self, abs_db_xsl, timestamp):
39 """ Try to get the compiled xsl file from the cache.
40
41 @param abs_db_xsl: The input xsl file of which we should find
42 @@ -92,25 +85,27 @@
43 @param errors: Should we do logging?
44 """
45 try:
46 - if self.cached_name.content() != abs_db_xsl:
47 - if log:
48 - logging.debug(
49 - "Docbook XSL file configuration changed from %s to %s" %
50 - (cached_name.content(), abs_db_xsl)
51 - )
52 - elif self.cached.needsUpdate(abs_db_xsl):
53 - if log:
54 - logging.debug("Docbook XSL file changed")
55 - else:
56 - # Good, we got a cache hit!
57 - compiled = self.cached.content()
58 - if log:
59 - logging.debug("Got compiled Docbook XSL file from cache")
60 - return compiled
61 + (cfilename, ctimestamp, compiled) = self.cached_xsl.content()
62 except caching.CacheError:
63 - if log:
64 - logging.debug("Got cache error for compiled XSL file")
65 - return None
66 + logging.debug("Got cache error for compiled XSL file")
67 + return None
68 +
69 + if (abs_db_xsl != cfilename):
70 + logging.debug(
71 + "Docbook XSL file configuration changed from %s to %s" %
72 + (cfilename, abs_db_xsl)
73 + )
74 + return None
75 +
76 + if (timestamp != ctimestamp):
77 + # Note that this check is only partially sufficient, since
78 + # the xsl typically includes a bunch of other files as well.
79 + logging.debug("Docbook XSL file changed")
80 + return None
81 +
82 + # Good, we got a cache hit!
83 + logging.debug("Got compiled Docbook XSL file from cache")
84 + return compiled
85
86 def append_stylesheet(self):
87 """"
88 @@ -118,32 +113,27 @@
89 """
90 abs_db_xsl = os.path.abspath(self.db_xsl)
91
92 - compiled = self.get_cached_stylesheet(abs_db_xsl)
93 + try:
94 + timestamp = os.path.getmtime(abs_db_xsl)
95 + compiled = self.get_cached_stylesheet(abs_db_xsl, timestamp)
96 + except os.error:
97 + logging.warning(
98 + "Couldn't get mtime of Docbook XSL file: '%s'" %
99 + (abs_db_xsl)
100 + )
101 + timestamp = 0
102 + compiled = None
103
104 if compiled is None:
105 # Recompile the XSL file
106 - logging.debug("(Re)compiling Docbook XSL file: '%s'" % (abs_db_xsl))
107 + logging.debug(
108 + "(Re)compiling Docbook XSL file: '%s'" %
109 + (abs_db_xsl)
110 + )
111 compiled = _compile_xsl(abs_db_xsl)
112 - # Check the cache again (another thread might have filled
113 - # the cache by now) and update the cache if that's not the
114 - # case. Don't do any logging of the result, since that might
115 - # be confusing.
116 - if (self.get_cached_stylesheet(abs_db_xsl, log=False) is None):
117 - # We first remove the old cached_name, to prevent an
118 - # inconsistent situation and invalid cache hits after
119 - # changing the xsl filename configuration. This does
120 - # allow for possibly indefinite recompiling, if
121 - # everytime a new thread triggers recompilation just
122 - # between the remove and update of cached_name. However,
123 - # the recheck of the cache combined with the long time
124 - # needed to compile the xsl should make this case
125 - # extremely unlikely.
126 - self.cached_name.remove()
127 - self.cached.update(compiled)
128 - self.cached_name.update(abs_db_xsl)
129 - logging.debug("Saved compiled Docbook XSL file to cache")
130 - else:
131 - logging.debug("Skipping saving of compiled Docbook XSL file to cache")
132 + # Save compiled file to cache
133 + self.cached_xsl.update((abs_db_xsl, timestamp, compiled))
134 + logging.debug("Saved compiled Docbook XSL file to cache")
135
136 self.processor.appendStylesheetInstance(compiled)
137
138 @@ -243,11 +233,7 @@
139 # Append Stylesheet
140 db_processor.appendStylesheet(sty_isrc)
141
142 - # Pickled stylesheet will be self.abs_db_compiled_xsl file
143 - db_root = db_processor.stylesheet.root
144 -
145 - return db_root
146 -
147 + return db_processor.stylesheet.root
148
149 def _splitResult(iterator, result):
150 startpos = 0
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.You are not allowed to attach a file to this page.