diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-29 00:09:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-29 00:09:15 +0300 |
commit | 8831c2df7fa3f1bb567e284e4b8c0a4f441e74b3 (patch) | |
tree | 36b1b430075ff6e63524be14585dbb614e893e8c /app | |
parent | 1c8fa70f9d0818e2a82089c8643a6e455bca47fd (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/models/concerns/cache_markdown_field.rb | 18 | ||||
-rw-r--r-- | app/models/group.rb | 14 | ||||
-rw-r--r-- | app/models/project.rb | 8 | ||||
-rw-r--r-- | app/models/snippet.rb | 4 |
4 files changed, 35 insertions, 9 deletions
diff --git a/app/models/concerns/cache_markdown_field.rb b/app/models/concerns/cache_markdown_field.rb index 9713e79f525..cc13f279c4d 100644 --- a/app/models/concerns/cache_markdown_field.rb +++ b/app/models/concerns/cache_markdown_field.rb @@ -20,6 +20,10 @@ module CacheMarkdownField false end + def can_cache_field?(field) + true + end + # Returns the default Banzai render context for the cached markdown field. def banzai_render_context(field) raise ArgumentError.new("Unknown field: #{field.inspect}") unless @@ -38,17 +42,23 @@ module CacheMarkdownField context end - # Update every column in a row if any one is invalidated, as we only store - # one version per row - def refresh_markdown_cache + def rendered_field_content(markdown_field) + return unless can_cache_field?(markdown_field) + options = { skip_project_check: skip_project_check? } + Banzai::Renderer.cacheless_render_field(self, markdown_field, options) + end + # Update every applicable column in a row if any one is invalidated, as we only store + # one version per row + def refresh_markdown_cache updates = cached_markdown_fields.markdown_fields.map do |markdown_field| [ cached_markdown_fields.html_field(markdown_field), - Banzai::Renderer.cacheless_render_field(self, markdown_field, options) + rendered_field_content(markdown_field) ] end.to_h + updates['cached_markdown_version'] = latest_cached_markdown_version updates.each { |field, data| write_markdown_field(field, data) } diff --git a/app/models/group.rb b/app/models/group.rb index a5337f19b38..d6a4af5af15 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -406,11 +406,15 @@ class Group < Namespace end def ci_variables_for(ref, project) - list_of_ids = [self] + ancestors - variables = Ci::GroupVariable.where(group: list_of_ids) - variables = variables.unprotected unless project.protected_for?(ref) - variables = variables.group_by(&:group_id) - list_of_ids.reverse.flat_map { |group| variables[group.id] }.compact + cache_key = "ci_variables_for:group:#{self&.id}:project:#{project&.id}:ref:#{ref}" + + ::Gitlab::SafeRequestStore.fetch(cache_key) do + list_of_ids = [self] + ancestors + variables = Ci::GroupVariable.where(group: list_of_ids) + variables = variables.unprotected unless project.protected_for?(ref) + variables = variables.group_by(&:group_id) + list_of_ids.reverse.flat_map { |group| variables[group.id] }.compact + end end def group_member(user) diff --git a/app/models/project.rb b/app/models/project.rb index 5ec43de21fe..f72e777c004 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1963,6 +1963,14 @@ class Project < ApplicationRecord end def ci_variables_for(ref:, environment: nil) + cache_key = "ci_variables_for:project:#{self&.id}:ref:#{ref}:environment:#{environment}" + + ::Gitlab::SafeRequestStore.fetch(cache_key) do + uncached_ci_variables_for(ref: ref, environment: environment) + end + end + + def uncached_ci_variables_for(ref:, environment: nil) result = if protected_for?(ref) variables else diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 8bba79bd944..233834dbaf9 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -301,6 +301,10 @@ class Snippet < ApplicationRecord repository.update!(shard_name: repository_storage, disk_path: disk_path) end + def can_cache_field?(field) + field != :content || MarkupHelper.gitlab_markdown?(file_name) + end + class << self # Searches for snippets with a matching title or file name. # |