From 747411a09748c4bcb02f2f1e5a795be2c49b1b45 Mon Sep 17 00:00:00 2001 From: RhodeCode Admin Date: Thu, 13 Oct 2022 13:24:37 +0200 Subject: [PATCH] helpers: use a small compilation cache to not re-compile same patterns over and over. --- rhodecode/lib/helpers.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py index 72dd8287..23640def 100644 --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -1666,22 +1666,26 @@ pr_pattern_re = regex.compile(r'(?:(?:^!)|(?: !))(\d+)') allowed_link_formats = [ 'html', 'rst', 'markdown', 'html+hovercard', 'rst+hovercard', 'markdown+hovercard'] +compile_cache = { + +} + def process_patterns(text_string, repo_name, link_format='html', active_entries=None): if link_format not in allowed_link_formats: raise ValueError('Link format can be only one of:{} got {}'.format( allowed_link_formats, link_format)) + issues_data = [] + errors = [] + new_text = text_string if active_entries is None: log.debug('Fetch active issue tracker patterns for repo: %s', repo_name) active_entries = get_active_pattern_entries(repo_name) - issues_data = [] - errors = [] - new_text = text_string - log.debug('Got %s pattern entries to process', len(active_entries)) + for uid, entry in active_entries.items(): if not (entry['pat'] and entry['url']): @@ -1693,6 +1697,8 @@ def process_patterns(text_string, repo_name, link_format='html', active_entries= if entry.get('pat_compiled'): pattern = entry['pat_compiled'] + elif entry['pat'] in compile_cache: + pattern = compile_cache[entry['pat']] else: try: pattern = regex.compile(r'%s' % entry['pat']) @@ -1701,6 +1707,7 @@ def process_patterns(text_string, repo_name, link_format='html', active_entries= log.exception('issue tracker pattern: `%s` failed to compile', regex_err) errors.append(regex_err) continue + compile_cache[entry['pat']] = pattern data_func = partial( _process_url_func, repo_name=repo_name, entry=entry, uid=uid,