slimmer 10.1.2 → 10.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf1be878da47f0dac30e1d4da176bcf05377d3f1
4
- data.tar.gz: f2097a93fe3ec0695f44930d4f1ea17d545c81a3
3
+ metadata.gz: c68306884f599c1b2c0ec09ab343531783a40465
4
+ data.tar.gz: 3c6e6dfed7ca6d702b47f36a93f933d4a842fbc0
5
5
  SHA512:
6
- metadata.gz: 9efdaad3a7bfc7f8a505c3b57b8c1bea7348171dd063591b6973940fc2f552e70f825e1ea76141000256cde9a8dbd9ea444080855be3ef953b2bd965614f30ca
7
- data.tar.gz: fae17cd6cd6aa4b095f3e9e58833872ac6ab4166be469a164bd20aecf1853335a516c011c660c8c202ed3603e436dae5465da12e263c43da90ddec6fc86c1865
6
+ metadata.gz: 25903ce0805883946d9485de6db6526f583f3e93673dfae7b36c30808ae054d9a2248658f3971a7d75480457995810fe78cb1cf36c4a1461c3e230d16ba29579
7
+ data.tar.gz: f2de6e5c472d76b9f5ce879591efe8479e8ae53711182c076805a18ad7c2b83d227942c8f0a2acfc0cf38479d153eca24e77ee432eb5e22fc0b8d1be9bcd2625
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 10.1.3
2
+
3
+ * Fix memory leak in components
4
+
1
5
  # 10.1.2
2
6
 
3
7
  * Bugfix for request URI's encoded as ASCII
@@ -5,12 +5,6 @@ module Slimmer
5
5
  class ComponentResolver < ::ActionView::Resolver
6
6
  TEST_TAG_NAME = 'test-govuk-component'
7
7
 
8
- def self.caching
9
- # this turns off the default ActionView::Resolver caching which caches
10
- # all templates for the duration of the current process in production
11
- false
12
- end
13
-
14
8
  def find_templates(name, prefix, partial, details, outside_app_allowed = false)
15
9
  return [] unless prefix == 'govuk_component'
16
10
 
@@ -17,17 +17,41 @@ module Slimmer
17
17
 
18
18
  # @private
19
19
  def add_govuk_components
20
- append_view_path Slimmer::ComponentResolver.new
20
+ append_view_path GovukComponents.expiring_resolver_cache.resolver
21
21
 
22
22
  return if slimmer_backend_included?
23
23
  I18n.backend = I18n::Backend::Chain.new(I18n.backend, Slimmer::I18nBackend.new)
24
24
  end
25
25
 
26
+ # @private
27
+ def self.expiring_resolver_cache
28
+ @expiring_resolver_cache ||= TimedExpirationResolverCache.new
29
+ end
30
+
26
31
  private
27
32
 
28
33
  def slimmer_backend_included?
29
34
  I18n.backend.is_a?(I18n::Backend::Chain) &&
30
35
  I18n.backend.backends.any? { |b| b.is_a? Slimmer::I18nBackend }
31
36
  end
37
+
38
+ # Slimmer::ComponentResolver instantiates a lot of large objects and leaks
39
+ # memory. This class will cache the resolver so that it doesn't have to
40
+ # create new ActionView::Template objects for each request. The cache is
41
+ # timed to allow frontends to pick up changes made to components in `static`.
42
+ class TimedExpirationResolverCache
43
+ def initialize
44
+ @cache_last_reset = Time.now
45
+ end
46
+
47
+ def resolver
48
+ if (@cache_last_reset + Slimmer::CACHE_TTL) < Time.now
49
+ @resolver = nil
50
+ @cache_last_reset = Time.now
51
+ end
52
+
53
+ @resolver ||= Slimmer::ComponentResolver.new
54
+ end
55
+ end
32
56
  end
33
57
  end
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = '10.1.2'
2
+ VERSION = '10.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.1.2
4
+ version: 10.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-24 00:00:00.000000000 Z
11
+ date: 2017-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri