diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-05-12 15:19:27 +0200 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-05-22 21:55:43 +0200 |
commit | ebede2b3ff1c2b089529c4f9d6268641580e280b (patch) | |
tree | 08d0463762501180bf45444cd88cacf085e9bcd4 /app/models/environment.rb | |
parent | 50a00442285973a390fa448d189ee43cd700d668 (diff) | |
download | gitlab-ce-ebede2b3ff1c2b089529c4f9d6268641580e280b.tar.gz |
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
Diffstat (limited to 'app/models/environment.rb')
-rw-r--r-- | app/models/environment.rb | 11 |
1 files changed, 11 insertions, 0 deletions
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 |