From ebede2b3ff1c2b089529c4f9d6268641580e280b Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Fri, 12 May 2017 15:19:27 +0200 Subject: Use etag caching for environments JSON For the index view, the environments can now be requested every 15 seconds. Any transition state of a projects environments will trigger a cache invalidation action. Fixes gitlab-org/gitlab-ce#31701 --- app/models/environment.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'app/models/environment.rb') diff --git a/app/models/environment.rb b/app/models/environment.rb index 61572d8d69a..07722d9a59e 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -57,6 +57,10 @@ class Environment < ActiveRecord::Base state :available state :stopped + + after_transition do |environment| + environment.expire_etag_cache + end end def predefined_variables @@ -196,6 +200,13 @@ class Environment < ActiveRecord::Base [external_url, public_path].join('/') end + def expire_etag_cache + Gitlab::EtagCaching::Store.new.tap do |store| + store.touch(Gitlab::Routing.url_helpers + .namespace_project_environments_path(project.namespace, project)) + end + end + private # Slugifying a name may remove the uniqueness guarantee afforded by it being -- cgit v1.2.1 From f4aa01053ed39a265ddfd9ee6e9618bd3406e59d Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Tue, 30 May 2017 23:56:26 +0200 Subject: Test etag cache key changing value --- app/models/environment.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'app/models/environment.rb') diff --git a/app/models/environment.rb b/app/models/environment.rb index 07722d9a59e..6211a5c1e63 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -202,11 +202,16 @@ class Environment < ActiveRecord::Base def expire_etag_cache Gitlab::EtagCaching::Store.new.tap do |store| - store.touch(Gitlab::Routing.url_helpers - .namespace_project_environments_path(project.namespace, project)) + store.touch(etag_cache_key) end end + def etag_cache_key + Gitlab::Routing.url_helpers.namespace_project_environments_path( + project.namespace, + project) + end + private # Slugifying a name may remove the uniqueness guarantee afforded by it being -- cgit v1.2.1