##// END OF EJS Templates
summary: Avoid to re-fetch Node object
johbo -
r774:d9e392db default
parent child Browse files
Show More
@@ -63,14 +63,16 b' class SummaryController(BaseRepoControll'
63 63 @cache_region('long_term')
64 64 def _generate_readme(cache_key):
65 65 readme_data = None
66 readme_file = None
66 readme_node = None
67 readme_filename = None
67 68 commit = self._get_landing_commit_or_none(db_repo)
68 69 if commit:
69 70 log.debug("Searching for a README file.")
70 readme_file = ReadmeFinder(default_renderer).search(commit)
71 if readme_file:
72 readme_data = self._render_readme_or_none(commit, readme_file)
73 return readme_data, readme_file
71 readme_node = ReadmeFinder(default_renderer).search(commit)
72 if readme_node:
73 readme_data = self._render_readme_or_none(commit, readme_node)
74 readme_filename = readme_node.path
75 return readme_data, readme_filename
74 76
75 77 invalidator_context = CacheKey.repo_context_cache(
76 78 _generate_readme, repo_name, CacheKey.CACHE_TYPE_README)
@@ -93,13 +95,13 b' class SummaryController(BaseRepoControll'
93 95 log.exception(
94 96 "Problem getting commit when trying to render the README.")
95 97
96 def _render_readme_or_none(self, commit, readme_file):
98 def _render_readme_or_none(self, commit, readme_node):
97 99 log.debug(
98 'Found README file `%s` rendering...', readme_file)
100 'Found README file `%s` rendering...', readme_node.path)
99 101 renderer = MarkupRenderer()
100 node = commit.get_node(readme_file)
101 102 try:
102 return renderer.render(node.content, filename=readme_file)
103 return renderer.render(
104 readme_node.content, filename=readme_node.file)
103 105 except Exception:
104 106 log.exception(
105 107 "Exception while trying to render the README")
@@ -987,7 +987,7 b' class ReadmeFinder:'
987 987 matches = self._match_readmes(nodes)
988 988 matches = self._sort_according_to_priority(matches)
989 989 if matches:
990 return matches[0].path
990 return matches[0]
991 991
992 992 paths = self._match_paths(nodes)
993 993 paths = self._sort_paths_according_to_priority(paths)
@@ -54,29 +54,29 b' class CommitUtility:'
54 54 def test_no_matching_file_returns_none(commit_util):
55 55 commit = commit_util.commit_with_files(['LIESMICH'])
56 56 finder = ReadmeFinder(default_renderer='rst')
57 filename = finder.search(commit)
58 assert filename is None
57 filenode = finder.search(commit)
58 assert filenode is None
59 59
60 60
61 61 def test_matching_file_returns_the_file_name(commit_util):
62 62 commit = commit_util.commit_with_files(['README'])
63 63 finder = ReadmeFinder(default_renderer='rst')
64 filename = finder.search(commit)
65 assert filename == 'README'
64 filenode = finder.search(commit)
65 assert filenode.path == 'README'
66 66
67 67
68 68 def test_matching_file_with_extension(commit_util):
69 69 commit = commit_util.commit_with_files(['README.rst'])
70 70 finder = ReadmeFinder(default_renderer='rst')
71 filename = finder.search(commit)
72 assert filename == 'README.rst'
71 filenode = finder.search(commit)
72 assert filenode.path == 'README.rst'
73 73
74 74
75 75 def test_prefers_readme_without_extension(commit_util):
76 76 commit = commit_util.commit_with_files(['README.rst', 'Readme'])
77 77 finder = ReadmeFinder()
78 filename = finder.search(commit)
79 assert filename == 'Readme'
78 filenode = finder.search(commit)
79 assert filenode.path == 'Readme'
80 80
81 81
82 82 @pytest.mark.parametrize('renderer, expected', [
@@ -87,20 +87,20 b' def test_prefers_renderer_extensions(com'
87 87 commit = commit_util.commit_with_files(
88 88 ['readme.rst', 'readme.md', 'readme.txt'])
89 89 finder = ReadmeFinder(default_renderer=renderer)
90 filename = finder.search(commit)
91 assert filename == expected
90 filenode = finder.search(commit)
91 assert filenode.path == expected
92 92
93 93
94 94 def test_finds_readme_in_subdirectory(commit_util):
95 95 commit = commit_util.commit_with_files(['doc/README.rst', 'LIESMICH'])
96 96 finder = ReadmeFinder()
97 filename = finder.search(commit)
98 assert filename == 'doc/README.rst'
97 filenode = finder.search(commit)
98 assert filenode.path == 'doc/README.rst'
99 99
100 100
101 101 def test_prefers_subdirectory_with_priority(commit_util):
102 102 commit = commit_util.commit_with_files(
103 103 ['Doc/Readme.rst', 'Docs/Readme.rst'])
104 104 finder = ReadmeFinder()
105 filename = finder.search(commit)
106 assert filename == 'Doc/Readme.rst'
105 filenode = finder.search(commit)
106 assert filenode.path == 'Doc/Readme.rst'
General Comments 0
You need to be logged in to leave comments. Login now