Marius Gedminas  committed d2f06a2

Bugfix: logview was unreasonably slow in the presence of may log messages.

Turns out the slowdown was in re.sub() with a long replacement string; I
rewrote the code to use re.split() instead and now it's fast.

  • Participants
  • Parent commits 98b5036

Comments (0)

Files changed (1)

File dozer/

                                  tottime=tottime, start=start)
-            response.body = re.sub(r'<body([^>]*)>', r'<body\1>%s' % logbar, response.body)
+            logbar = logbar.encode('ascii', 'xmlcharrefreplace')
+            parts = re.split(r'(<body[^>]*>)', response.body)
+            # parts = ['preamble', '<body ...>', 'text'] or just ['text']
+            # we want to insert our logbar after <body> (if it exists) and
+            # in front of text
+            response.body = ''.join(parts[:-1] + [logbar] + parts[-1:])
         return response(environ, start_response)
     def render(self, name, **vars):