From b7303b65b1a761c7ad7ed9eed993ad55fcecb953 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Wed, 11 Oct 2017 16:48:43 +0100 Subject: Cache issuable template names We were looking these up on each request to an issue page, because the form is pre-filled, as is the template dropdown. That was unnecessary: we could just treat these as 'special' repository files (like the rendered README) and cache them in Redis until they change on a push. --- app/models/repository.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'app/models/repository.rb') diff --git a/app/models/repository.rb b/app/models/repository.rb index d725c65081d..bf526ca1762 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -34,7 +34,8 @@ class Repository CACHED_METHODS = %i(size commit_count rendered_readme contribution_guide changelog license_blob license_key gitignore koding_yml gitlab_ci_yml branch_names tag_names branch_count - tag_count avatar exists? empty? root_ref has_visible_content?).freeze + tag_count avatar exists? empty? root_ref has_visible_content? + issue_template_names merge_request_template_names).freeze # Methods that use cache_method but only memoize the value MEMOIZED_CACHED_METHODS = %i(license empty_repo?).freeze @@ -50,7 +51,9 @@ class Repository gitignore: :gitignore, koding: :koding_yml, gitlab_ci: :gitlab_ci_yml, - avatar: :avatar + avatar: :avatar, + issue_template: :issue_template_names, + merge_request_template: :merge_request_template_names }.freeze # Wraps around the given method and caches its output in Redis and an instance @@ -535,6 +538,16 @@ class Repository end cache_method :avatar + def issue_template_names + Gitlab::Template::IssueTemplate.dropdown_names(project) + end + cache_method :issue_template_names, fallback: [] + + def merge_request_template_names + Gitlab::Template::MergeRequestTemplate.dropdown_names(project) + end + cache_method :merge_request_template_names, fallback: [] + def readme if readme = tree(:head)&.readme ReadmeBlob.new(readme, self) -- cgit v1.2.1