Commit f5340667 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Expire etag cache to force environments.json reload

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