Commit 71090231 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab master

parents 3dc2ee49 c8b9ec0a
......@@ -667,6 +667,17 @@ entry.
- [Add missing metrics information](gitlab-org/gitlab@89cd7fe3b95323e635b2d73e08549b2e6153dc4d) ([merge request](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61772/edit))
- [Track usage of the resolve UI](gitlab-org/gitlab@35c8e30fce288cecefcf2f7c0077d4608e696519) ([merge request](gitlab-org/gitlab!61654))
## 13.12.7 (2021-07-05)
### Fixed (2 changes)
- [Fix state value in the lfs_object_registry table](gitlab-org/gitlab@feca70558108299a9b7b499e4461b59b7c140ef7) ([merge request](gitlab-org/gitlab!65466)) **GitLab Enterprise Edition**
- [Fix pages deployment storage migration](gitlab-org/gitlab@4e806a7b5e0eef8d88bcdb68724c6b7bf3c08293) ([merge request](gitlab-org/gitlab!65366))
### Changed (1 change)
- [Move migration to a pre-deployment migration](gitlab-org/gitlab@d02fcd44b3dd797e18221e4e91ab913372bdf18a) ([merge request](gitlab-org/gitlab!65466)) **GitLab Enterprise Edition**
## 13.12.6 (2021-07-01)
### Added (1 change)
......
......@@ -71,15 +71,21 @@ module Namespaces
traversal_ids.present?
end
def root_ancestor
return super if parent.nil?
return super unless persisted?
def use_traversal_ids_for_root_ancestor?
return false unless Feature.enabled?(:use_traversal_ids_for_root_ancestor, default_enabled: :yaml)
return super if traversal_ids.blank?
return super unless Feature.enabled?(:use_traversal_ids_for_root_ancestor, default_enabled: :yaml)
traversal_ids.present?
end
def root_ancestor
return super unless use_traversal_ids_for_root_ancestor?
strong_memoize(:root_ancestor) do
Namespace.find_by(id: traversal_ids.first)
if parent.nil?
self
else
Namespace.find_by(id: traversal_ids.first)
end
end
end
......
......@@ -11,12 +11,10 @@ module API
include Gitlab::Cache::Helpers
# @return [Hash]
DEFAULT_CACHE_OPTIONS = {
race_condition_ttl: 5.seconds
race_condition_ttl: 5.seconds,
version: 1
}.freeze
# @return Integer
VERSION = 1
# @return [Array]
PAGINATION_HEADERS = %w[X-Per-Page X-Page X-Next-Page X-Prev-Page Link X-Total X-Total-Pages].freeze
......@@ -81,7 +79,7 @@ module API
def cache_action(key, **custom_cache_opts)
cache_opts = apply_default_cache_options(custom_cache_opts)
json, cached_headers = cache.fetch([key, VERSION], **cache_opts) do
json, cached_headers = cache.fetch(key, **cache_opts) do
response = yield
cached_body = response.is_a?(Gitlab::Json::PrecompiledJson) ? response.to_s : Gitlab::Json.dump(response.as_json)
......
......@@ -81,7 +81,7 @@ RSpec.describe API::Helpers::Caching, :use_clean_rails_redis_caching do
expected_kwargs = described_class::DEFAULT_CACHE_OPTIONS.merge(kwargs)
expect(expensive_thing).to receive(:do_very_expensive_action).once
expect(instance.cache).to receive(:fetch).with([cache_key, 1], **expected_kwargs).exactly(5).times.and_call_original
expect(instance.cache).to receive(:fetch).with(cache_key, **expected_kwargs).exactly(5).times.and_call_original
5.times { perform }
end
......@@ -96,6 +96,16 @@ RSpec.describe API::Helpers::Caching, :use_clean_rails_redis_caching do
expect(nested_call.to_s).to eq(subject.to_s)
end
context 'Cache versioning' do
it 'returns cache based on version parameter' do
result_1 = instance.cache_action(cache_key, **kwargs.merge(version: 1)) { 'Cache 1' }
result_2 = instance.cache_action(cache_key, **kwargs.merge(version: 2)) { 'Cache 2' }
expect(result_1.to_s).to eq('Cache 1'.to_json)
expect(result_2.to_s).to eq('Cache 2'.to_json)
end
end
context 'Cache for pagination headers' do
described_class::PAGINATION_HEADERS.each do |pagination_header|
context pagination_header do
......
......@@ -974,6 +974,14 @@ RSpec.describe Namespace do
end
end
shared_examples 'disabled feature flag when traversal_ids is blank' do
before do
namespace.traversal_ids = []
end
it { is_expected.to eq false }
end
describe '#use_traversal_ids?' do
let_it_be(:namespace, reload: true) { create(:namespace) }
......@@ -985,6 +993,8 @@ RSpec.describe Namespace do
end
it { is_expected.to eq true }
it_behaves_like 'disabled feature flag when traversal_ids is blank'
end
context 'when use_traversal_ids feature flag is false' do
......@@ -996,6 +1006,30 @@ RSpec.describe Namespace do
end
end
describe '#use_traversal_ids_for_root_ancestor?' do
let_it_be(:namespace, reload: true) { create(:namespace) }
subject { namespace.use_traversal_ids_for_root_ancestor? }
context 'when use_traversal_ids_for_root_ancestor feature flag is true' do
before do
stub_feature_flags(use_traversal_ids_for_root_ancestor: true)
end
it { is_expected.to eq true }
it_behaves_like 'disabled feature flag when traversal_ids is blank'
end
context 'when use_traversal_ids_for_root_ancestor feature flag is false' do
before do
stub_feature_flags(use_traversal_ids_for_root_ancestor: false)
end
it { is_expected.to eq false }
end
end
describe '#use_traversal_ids_for_ancestors?' do
let_it_be(:namespace, reload: true) { create(:namespace) }
......@@ -1007,6 +1041,8 @@ RSpec.describe Namespace do
end
it { is_expected.to eq true }
it_behaves_like 'disabled feature flag when traversal_ids is blank'
end
context 'when use_traversal_ids_for_ancestors? feature flag is false' do
......
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