Commit 824e39b0 authored by Alexandru Croitor's avatar Alexandru Croitor

Reset templates cache key

Change method name for fetching issue and merge request templates
which also resets the caching key. Also do not cache empty hash
on fallback but rather default to nil, which would make another
gitally request and cache a success value or be nil in case of failure
parent bb9e095a
......@@ -43,7 +43,7 @@ class Repository
changelog license_blob license_key gitignore
gitlab_ci_yml branch_names tag_names branch_count
tag_count avatar exists? root_ref merged_branch_names
has_visible_content? issue_template_names_by_category merge_request_template_names_by_category
has_visible_content? issue_template_names_hash merge_request_template_names_hash
user_defined_metrics_dashboard_paths xcode_project? has_ambiguous_refs?).freeze
# Methods that use cache_method but only memoize the value
......@@ -60,8 +60,8 @@ class Repository
gitignore: :gitignore,
gitlab_ci: :gitlab_ci_yml,
avatar: :avatar,
issue_template: :issue_template_names_by_category,
merge_request_template: :merge_request_template_names_by_category,
issue_template: :issue_template_names_hash,
merge_request_template: :merge_request_template_names_hash,
metrics_dashboard: :user_defined_metrics_dashboard_paths,
xcode_config: :xcode_project?
}.freeze
......@@ -573,15 +573,15 @@ class Repository
cache_method :avatar
# store issue_template_names as hash
def issue_template_names_by_category
def issue_template_names_hash
Gitlab::Template::IssueTemplate.repository_template_names(project)
end
cache_method :issue_template_names_by_category, fallback: {}
cache_method :issue_template_names_hash, fallback: {}
def merge_request_template_names_by_category
def merge_request_template_names_hash
Gitlab::Template::MergeRequestTemplate.repository_template_names(project)
end
cache_method :merge_request_template_names_by_category, fallback: {}
cache_method :merge_request_template_names_hash, fallback: {}
def user_defined_metrics_dashboard_paths
Gitlab::Metrics::Dashboard::RepoDashboardFinder.list_dashboards(project)
......
---
title: Reset description template names cache key to reload an updated templates structure
merge_request: 54614
author:
type: fixed
......@@ -108,7 +108,7 @@ module Gitlab
# Gitaly the actual template names within a given project's repository for all file templates
# other than `issue` and `merge request` description templates, which would instead
# overwrite the `template_names` method to return a redis cached version, by reading cached values
# from `repository.issue_template_names_by_category` and `repository.merge_request_template_names_by_category`
# from `repository.issue_template_names_hash` and `repository.merge_request_template_names_hash`
# methods.
def repository_template_names(project)
template_names_by_category(self.all(project))
......
......@@ -23,7 +23,7 @@ module Gitlab
# own caching mechanism to avoid the back and forth call jumps between finder and model.
#
# follow-up issue: https://gitlab.com/gitlab-org/gitlab/-/issues/300279
project.repository.issue_template_names_by_category
project.repository.issue_template_names_hash
end
def by_category(category, project = nil, empty_category_title: nil)
......
......@@ -23,7 +23,7 @@ module Gitlab
# own caching mechanism to avoid the back and forth call jumps between finder and model.
#
# follow-up issue: https://gitlab.com/gitlab-org/gitlab/-/issues/300279
project.repository.merge_request_template_names_by_category
project.repository.merge_request_template_names_hash
end
def by_category(category, project = nil, empty_category_title: nil)
......
......@@ -1949,8 +1949,8 @@ RSpec.describe Repository do
:root_ref,
:merged_branch_names,
:has_visible_content?,
:issue_template_names_by_category,
:merge_request_template_names_by_category,
:issue_template_names_hash,
:merge_request_template_names_hash,
:user_defined_metrics_dashboard_paths,
:xcode_project?,
:has_ambiguous_refs?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment