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 ...@@ -43,7 +43,7 @@ class Repository
changelog license_blob license_key gitignore changelog license_blob license_key gitignore
gitlab_ci_yml branch_names tag_names branch_count gitlab_ci_yml branch_names tag_names branch_count
tag_count avatar exists? root_ref merged_branch_names 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 user_defined_metrics_dashboard_paths xcode_project? has_ambiguous_refs?).freeze
# Methods that use cache_method but only memoize the value # Methods that use cache_method but only memoize the value
...@@ -60,8 +60,8 @@ class Repository ...@@ -60,8 +60,8 @@ class Repository
gitignore: :gitignore, gitignore: :gitignore,
gitlab_ci: :gitlab_ci_yml, gitlab_ci: :gitlab_ci_yml,
avatar: :avatar, avatar: :avatar,
issue_template: :issue_template_names_by_category, issue_template: :issue_template_names_hash,
merge_request_template: :merge_request_template_names_by_category, merge_request_template: :merge_request_template_names_hash,
metrics_dashboard: :user_defined_metrics_dashboard_paths, metrics_dashboard: :user_defined_metrics_dashboard_paths,
xcode_config: :xcode_project? xcode_config: :xcode_project?
}.freeze }.freeze
...@@ -573,15 +573,15 @@ class Repository ...@@ -573,15 +573,15 @@ class Repository
cache_method :avatar cache_method :avatar
# store issue_template_names as hash # store issue_template_names as hash
def issue_template_names_by_category def issue_template_names_hash
Gitlab::Template::IssueTemplate.repository_template_names(project) Gitlab::Template::IssueTemplate.repository_template_names(project)
end 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) Gitlab::Template::MergeRequestTemplate.repository_template_names(project)
end end
cache_method :merge_request_template_names_by_category, fallback: {} cache_method :merge_request_template_names_hash, fallback: {}
def user_defined_metrics_dashboard_paths def user_defined_metrics_dashboard_paths
Gitlab::Metrics::Dashboard::RepoDashboardFinder.list_dashboards(project) 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 ...@@ -108,7 +108,7 @@ module Gitlab
# Gitaly the actual template names within a given project's repository for all file templates # 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 # 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 # 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. # methods.
def repository_template_names(project) def repository_template_names(project)
template_names_by_category(self.all(project)) template_names_by_category(self.all(project))
......
...@@ -23,7 +23,7 @@ module Gitlab ...@@ -23,7 +23,7 @@ module Gitlab
# own caching mechanism to avoid the back and forth call jumps between finder and model. # 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 # 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 end
def by_category(category, project = nil, empty_category_title: nil) def by_category(category, project = nil, empty_category_title: nil)
......
...@@ -23,7 +23,7 @@ module Gitlab ...@@ -23,7 +23,7 @@ module Gitlab
# own caching mechanism to avoid the back and forth call jumps between finder and model. # 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 # 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 end
def by_category(category, project = nil, empty_category_title: nil) def by_category(category, project = nil, empty_category_title: nil)
......
...@@ -1949,8 +1949,8 @@ RSpec.describe Repository do ...@@ -1949,8 +1949,8 @@ RSpec.describe Repository do
:root_ref, :root_ref,
:merged_branch_names, :merged_branch_names,
:has_visible_content?, :has_visible_content?,
:issue_template_names_by_category, :issue_template_names_hash,
:merge_request_template_names_by_category, :merge_request_template_names_hash,
:user_defined_metrics_dashboard_paths, :user_defined_metrics_dashboard_paths,
:xcode_project?, :xcode_project?,
:has_ambiguous_refs? :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