# HG changeset patch # User Bartlomiej Wolynczyk # Date 2020-01-20 13:53:23 # Node ID 5286ca082fcf87b2308386743743c42b026b6bb8 # Parent ecf6f84c0439bb2717ad887f2e90064dbb7368e6 issue-tracker: cache active patterns in the template so we can re-use them when rendering comments. - before each render call fetched settings and patterns to process - in case of lots of commits/large pull-requests this took a loot of time. diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -1522,7 +1522,10 @@ def process_patterns(text_string, repo_n raise ValueError('Link format can be only one of:{} got {}'.format( allowed_formats, link_format)) - active_entries = active_entries or get_active_pattern_entries(repo_name) + if active_entries is None: + log.debug('Fetch active patterns for repo: %s', repo_name) + active_entries = get_active_pattern_entries(repo_name) + issues_data = [] new_text = text_string @@ -1580,6 +1583,7 @@ def urlify_commit_message(commit_text, r Parses given text message and makes proper links. issues are linked to given issue-server, and rest is a commit link """ + def escaper(_text): return _text.replace('<', '<').replace('>', '>') @@ -1636,7 +1640,7 @@ def renderer_from_filename(filename, exc def render(source, renderer='rst', mentions=False, relative_urls=None, - repo_name=None): + repo_name=None, active_pattern_entries=None): def maybe_convert_relative_links(html_source): if relative_urls: @@ -1651,7 +1655,8 @@ def render(source, renderer='rst', menti if repo_name: # process patterns on comments if we pass in repo name source, issues = process_patterns( - source, repo_name, link_format='rst') + source, repo_name, link_format='rst', + active_entries=active_pattern_entries) return literal( '
%s
' % @@ -1662,7 +1667,8 @@ def render(source, renderer='rst', menti if repo_name: # process patterns on comments if we pass in repo name source, issues = process_patterns( - source, repo_name, link_format='markdown') + source, repo_name, link_format='markdown', + active_entries=active_pattern_entries) return literal( '
%s
' % diff --git a/rhodecode/templates/changeset/changeset_file_comment.mako b/rhodecode/templates/changeset/changeset_file_comment.mako --- a/rhodecode/templates/changeset/changeset_file_comment.mako +++ b/rhodecode/templates/changeset/changeset_file_comment.mako @@ -5,7 +5,7 @@ ## <%namespace name="base" file="/base/base.mako"/> -<%def name="comment_block(comment, inline=False)"> +<%def name="comment_block(comment, inline=False, active_pattern_entries=None)"> <% pr_index_ver = comment.get_index_version(getattr(c, 'versions', [])) %> <% latest_ver = len(getattr(c, 'versions', [])) %> % if inline: @@ -156,7 +156,7 @@
- ${h.render(comment.text, renderer=comment.renderer, mentions=True, repo_name=getattr(c, 'repo_name', None))} + ${h.render(comment.text, renderer=comment.renderer, mentions=True, repo_name=getattr(c, 'repo_name', None), active_pattern_entries=active_pattern_entries)}
@@ -164,13 +164,17 @@ ## generate main comments <%def name="generate_comments(comments, include_pull_request=False, is_pull_request=False)"> + <% + active_pattern_entries = h.get_active_pattern_entries(getattr(c, 'repo_name', None)) + %> +
%for comment in comments:
## only render comments that are not from pull request, or from ## pull request and a status change %if not comment.pull_request or (comment.pull_request and comment.status_change) or include_pull_request: - ${comment_block(comment)} + ${comment_block(comment, active_pattern_entries=active_pattern_entries)} %endif
%endfor diff --git a/rhodecode/templates/codeblocks/diffs.mako b/rhodecode/templates/codeblocks/diffs.mako --- a/rhodecode/templates/codeblocks/diffs.mako +++ b/rhodecode/templates/codeblocks/diffs.mako @@ -60,12 +60,16 @@ return '%s_%s_%i' % (h.md5_safe(commit+f <% diffset_container_id = h.md5(diffset.target_ref) collapse_all = len(diffset.files) > collapse_when_files_over + active_pattern_entries = h.get_active_pattern_entries(getattr(c, 'repo_name', None)) %> %if use_comments: + +## Template for injecting comments
- ${inline_comments_container([], inline_comments)} + ${inline_comments_container([])}
+
@@ -259,7 +263,7 @@ return '%s_%s_%i' % (h.md5_safe(commit+f ## new/deleted/empty content case % if not filediff.hunks: ## Comment container, on "fakes" hunk that contains all data to render comments - ${render_hunk_lines(filediff, c.user_session_attrs["diffmode"], filediff.hunk_ops, use_comments=use_comments, inline_comments=inline_comments)} + ${render_hunk_lines(filediff, c.user_session_attrs["diffmode"], filediff.hunk_ops, use_comments=use_comments, inline_comments=inline_comments, active_pattern_entries=active_pattern_entries)} % endif %if filediff.limited_diff: @@ -299,7 +303,7 @@ return '%s_%s_%i' % (h.md5_safe(commit+f ${hunk.section_header} - ${render_hunk_lines(filediff, c.user_session_attrs["diffmode"], hunk, use_comments=use_comments, inline_comments=inline_comments)} + ${render_hunk_lines(filediff, c.user_session_attrs["diffmode"], hunk, use_comments=use_comments, inline_comments=inline_comments, active_pattern_entries=active_pattern_entries)} % endfor <% unmatched_comments = (inline_comments or {}).get(filediff.patch['filename'], {}) %> @@ -323,7 +327,7 @@ return '%s_%s_%i' % (h.md5_safe(commit+f - ${inline_comments_container(comments, inline_comments)} + ${inline_comments_container(comments, active_pattern_entries=active_pattern_entries)} %elif c.user_session_attrs["diffmode"] == 'sideside': @@ -348,7 +352,7 @@ return '%s_%s_%i' % (h.md5_safe(commit+f % if lineno.startswith('o'): - ${inline_comments_container(comments, inline_comments)} + ${inline_comments_container(comments, active_pattern_entries=active_pattern_entries)} % endif @@ -356,7 +360,7 @@ return '%s_%s_%i' % (h.md5_safe(commit+f % if lineno.startswith('n'): - ${inline_comments_container(comments, inline_comments)} + ${inline_comments_container(comments, active_pattern_entries=active_pattern_entries)} % endif @@ -415,7 +419,7 @@ return '%s_%s_%i' % (h.md5_safe(commit+f - ${inline_comments_container(comments_dict['comments'], inline_comments)} + ${inline_comments_container(comments_dict['comments'], active_pattern_entries=active_pattern_entries)} %elif c.user_session_attrs["diffmode"] == 'sideside': @@ -427,7 +431,7 @@ return '%s_%s_%i' % (h.md5_safe(commit+f - ${inline_comments_container(comments_dict['comments'], inline_comments)} + ${inline_comments_container(comments_dict['comments'], active_pattern_entries=active_pattern_entries)} %endif @@ -584,10 +588,11 @@ from rhodecode.lib.diffs import NEW_FILE -<%def name="inline_comments_container(comments, inline_comments)"> +<%def name="inline_comments_container(comments, active_pattern_entries=None)"> +
%for comment in comments: - ${commentblock.comment_block(comment, inline=True)} + ${commentblock.comment_block(comment, inline=True, active_pattern_entries=active_pattern_entries)} %endfor % if comments and comments[-1].outdated: