# HG changeset patch # User RhodeCode Admin # Date 2022-10-13 11:24:37 # Node ID ad73733931cbf8c1ce0451fe2acd2fd9ed2ba638 # Parent eadea78d87087151663b930ad93ecb0667879b1a helpers: use a small compilation cache to not re-compile same patterns over and over. diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -1666,22 +1666,26 @@ pr_pattern_re = regex.compile(r'(?:(?:^! 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_n 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_n 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,