# HG changeset patch # User Johannes Bornhold # Date 2016-09-08 11:05:55 # Node ID d9e392db2b1c23fdc19ca2ca4d56db6d046ca0f4 # Parent 0b23acc0fd09c80fb768f6b515096782adb2976b summary: Avoid to re-fetch Node object diff --git a/rhodecode/controllers/summary.py b/rhodecode/controllers/summary.py --- a/rhodecode/controllers/summary.py +++ b/rhodecode/controllers/summary.py @@ -63,14 +63,16 @@ class SummaryController(BaseRepoControll @cache_region('long_term') def _generate_readme(cache_key): readme_data = None - readme_file = None + readme_node = None + readme_filename = None commit = self._get_landing_commit_or_none(db_repo) if commit: log.debug("Searching for a README file.") - readme_file = ReadmeFinder(default_renderer).search(commit) - if readme_file: - readme_data = self._render_readme_or_none(commit, readme_file) - return readme_data, readme_file + readme_node = ReadmeFinder(default_renderer).search(commit) + if readme_node: + readme_data = self._render_readme_or_none(commit, readme_node) + readme_filename = readme_node.path + return readme_data, readme_filename invalidator_context = CacheKey.repo_context_cache( _generate_readme, repo_name, CacheKey.CACHE_TYPE_README) @@ -93,13 +95,13 @@ class SummaryController(BaseRepoControll log.exception( "Problem getting commit when trying to render the README.") - def _render_readme_or_none(self, commit, readme_file): + def _render_readme_or_none(self, commit, readme_node): log.debug( - 'Found README file `%s` rendering...', readme_file) + 'Found README file `%s` rendering...', readme_node.path) renderer = MarkupRenderer() - node = commit.get_node(readme_file) try: - return renderer.render(node.content, filename=readme_file) + return renderer.render( + readme_node.content, filename=readme_node.file) except Exception: log.exception( "Exception while trying to render the README") diff --git a/rhodecode/model/repo.py b/rhodecode/model/repo.py --- a/rhodecode/model/repo.py +++ b/rhodecode/model/repo.py @@ -987,7 +987,7 @@ class ReadmeFinder: matches = self._match_readmes(nodes) matches = self._sort_according_to_priority(matches) if matches: - return matches[0].path + return matches[0] paths = self._match_paths(nodes) paths = self._sort_paths_according_to_priority(paths) diff --git a/rhodecode/tests/models/test_repo_readme.py b/rhodecode/tests/models/test_repo_readme.py --- a/rhodecode/tests/models/test_repo_readme.py +++ b/rhodecode/tests/models/test_repo_readme.py @@ -54,29 +54,29 @@ class CommitUtility: def test_no_matching_file_returns_none(commit_util): commit = commit_util.commit_with_files(['LIESMICH']) finder = ReadmeFinder(default_renderer='rst') - filename = finder.search(commit) - assert filename is None + filenode = finder.search(commit) + assert filenode is None def test_matching_file_returns_the_file_name(commit_util): commit = commit_util.commit_with_files(['README']) finder = ReadmeFinder(default_renderer='rst') - filename = finder.search(commit) - assert filename == 'README' + filenode = finder.search(commit) + assert filenode.path == 'README' def test_matching_file_with_extension(commit_util): commit = commit_util.commit_with_files(['README.rst']) finder = ReadmeFinder(default_renderer='rst') - filename = finder.search(commit) - assert filename == 'README.rst' + filenode = finder.search(commit) + assert filenode.path == 'README.rst' def test_prefers_readme_without_extension(commit_util): commit = commit_util.commit_with_files(['README.rst', 'Readme']) finder = ReadmeFinder() - filename = finder.search(commit) - assert filename == 'Readme' + filenode = finder.search(commit) + assert filenode.path == 'Readme' @pytest.mark.parametrize('renderer, expected', [ @@ -87,20 +87,20 @@ def test_prefers_renderer_extensions(com commit = commit_util.commit_with_files( ['readme.rst', 'readme.md', 'readme.txt']) finder = ReadmeFinder(default_renderer=renderer) - filename = finder.search(commit) - assert filename == expected + filenode = finder.search(commit) + assert filenode.path == expected def test_finds_readme_in_subdirectory(commit_util): commit = commit_util.commit_with_files(['doc/README.rst', 'LIESMICH']) finder = ReadmeFinder() - filename = finder.search(commit) - assert filename == 'doc/README.rst' + filenode = finder.search(commit) + assert filenode.path == 'doc/README.rst' def test_prefers_subdirectory_with_priority(commit_util): commit = commit_util.commit_with_files( ['Doc/Readme.rst', 'Docs/Readme.rst']) finder = ReadmeFinder() - filename = finder.search(commit) - assert filename == 'Doc/Readme.rst' + filenode = finder.search(commit) + assert filenode.path == 'Doc/Readme.rst'