Commit f5340667 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Expire etag cache to force environments.json reload

parent 83d4d557
......@@ -41,7 +41,7 @@
return !this.isLoading && this.isEmpty;
},
instanceTitle() {
return n__('Instance', 'Instances', this.deployBoardData.instances);
return n__('Instance', 'Instances', this.deployBoardData.instances.length);
},
projectName() {
return '<projectname>';
......
......@@ -7,7 +7,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
before_action :authorize_admin_environment!, only: [:terminal, :terminal_websocket_authorize]
before_action :environment, only: [:show, :edit, :update, :stop, :terminal, :terminal_websocket_authorize, :metrics]
before_action :verify_api_request!, only: :terminal_websocket_authorize
before_action :refresh_rollout_status, only: [:index]
before_action :expire_etag_cache, only: [:index]
def index
@environments = project.environments
......@@ -148,8 +148,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController
Gitlab::Workhorse.verify_api_request!(request.headers)
end
def refresh_rollout_status
environment.rollout_status
def expire_etag_cache
return if request.format.json?
# this forces to reload json content
Gitlab::EtagCaching::Store.new.tap do |store|
store.touch(project_environments_path(project, format: :json))
end
end
def environment_params
......
......@@ -80,9 +80,11 @@ module ReactiveCaching
locking_reactive_cache(*args) do
within_reactive_cache_lifetime(*args) do
enqueuing_update(*args) do
value = calculate_reactive_cache(*args)
Rails.cache.write(full_reactive_cache_key(*args), value)
reactive_cache_updated(*args)
key = full_reactive_cache_key(*args)
new_value = calculate_reactive_cache(*args)
old_value = Rails.cache.read(key)
Rails.cache.write(key, new_value)
reactive_cache_updated(*args) if new_value != old_value
end
end
end
......
......@@ -19,9 +19,9 @@ module EE
def reactive_cache_updated
super
Gitlab::EtagCaching::Store.new.tap do |store|
::Gitlab::EtagCaching::Store.new.tap do |store|
store.touch(
Gitlab::Routing.url_helpers.project_environments_path(project, format: :json))
::Gitlab::Routing.url_helpers.project_environments_path(project, format: :json))
end
end
......
......@@ -23,6 +23,13 @@ describe Projects::EnvironmentsController do
expect(response).to have_http_status(:ok)
end
it 'expires etag cache to force reload environments list' do
expect_any_instance_of(Gitlab::EtagCaching::Store)
.to receive(:touch).with(project_environments_path(project, format: :json))
get :index, environment_params
end
end
context 'when requesting JSON response for folders' do
......
......@@ -115,10 +115,11 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
go!
end
it "calls a reactive_cache_updated after updated" do
expect(instance).to receive(:reactive_cache_updated)
it "calls a reactive_cache_updated only once if content did not change on subsequent update" do
expect(instance).to receive(:calculate_reactive_cache).twice
expect(instance).to receive(:reactive_cache_updated).once
go!
2.times { instance.exclusively_update_reactive_cache! }
end
context 'and #calculate_reactive_cache raises an exception' 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