asset_ram 0.2.0 → 1.0.0

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
  SHA256:
3
- metadata.gz: 05464224fe91ef9aeb8784b87a9331802f9f1625f13e75969f672dccd4548dcd
4
- data.tar.gz: 1c5c4845548975b31204a71da7cdd8410b69c4806b191adc8c2047669a6cfd56
3
+ metadata.gz: af7a1812a96587aa5579767e82758e5b898b554dd28ef0c107c1f523166fa7c8
4
+ data.tar.gz: ecc5d98ecc9c2fb65589d96068bd71320e0a6844881e8ec1f511061367aef973
5
5
  SHA512:
6
- metadata.gz: 553e142c91b2dc4a5d4f1ff379524c65be3400d17498bba2cd549f81d4970077f037e4d329a3ec1d327e67e18d39f61b0ae946bf3e7e053c4f15ecef1c38f384
7
- data.tar.gz: cd10e4447bdbaeeb29d795f7862b33dea15320a5fc240a165850785be2d53da04da1d96979eb628edfecb01bd5e692f26c6dacc10230083a0e1401a83f4970a4
6
+ metadata.gz: e7df956fa67fa0900285f570501e6d6dea99744394e9a8ef9824f08c12008a9cf68373faa27216017a7b43ed4ab6bee33295f9d3976cc1f1d56091e8839ce462
7
+ data.tar.gz: cf583732e4974af18fab12dc9ee31bde5ae1f963fe842850bd0e5d6aace773eb99bd762eccaae12e1a7a3def93b69eb75c8eabf62f0bd95216e2a8a162dbbe9d
data/README.md CHANGED
@@ -1,28 +1,168 @@
1
1
  # AssetRam
2
2
 
3
- In a nutshell, for [a typical dynamic page](https://texas.public.law/statutes/tex._fam._code_section_1.001) in my Rails app, I get:
3
+ ## Tests in Production: allocation savings comes from avoiding certain rendering
4
4
 
5
- * 71% reduction in execution time
6
- * 83% reduction in allocations
5
+ Here's where the savings come from:
6
+
7
+ ```ruby
8
+ = AssetRam::Helper.cache { render 'footer' }
9
+ ```
10
+
11
+ My site's footer is static except for the asset links to e.g. social media icons.
7
12
 
8
- My app has been amazingly efficient since using these: memory usage stays flat at just 50% usage (512MB) for 4 Puma workers. It's very quick, with production response times averaging 37ms on a Heroku 1GB Standard-2x Dyno.
9
13
 
14
+ ### Production comparison test #1: https://texas.public.law/statutes/tex._fam._code_section_1.001
10
15
 
11
- ## Example stats for [the page](https://texas.public.law/statutes/tex._fam._code_section_1.001)
16
+ * 17% fewer allocations (5315 vs. 6414)
17
+ * 1,099 allocations saved by simply not re-rendering the footer views.
18
+ * 7ms slower
12
19
 
13
- Without AssetRam:
14
20
 
15
21
  ```
16
- Completed 200 OK in 38ms (Views: 34.2ms | ActiveRecord: 0.9ms | Allocations: 30332)
22
+ 2021-09-26T18:14:29.928482+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Started GET "/statutes/tex._fam._code_section_1.001" for 172.70.45.212 at 2021-09-26 18:14:29 +0000
23
+ 2021-09-26T18:14:29.929520+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Processing by StatutesController#show as HTML
24
+ 2021-09-26T18:14:29.929537+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Parameters: {"compilation"=>"statutes", "id"=>"tex._fam._code_section_1.001"}
25
+ 2021-09-26T18:14:29.933509+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Statute Load (1.4ms) SELECT "statutes".* FROM "statutes" WHERE (LOWER(citation) = 'tex. fam. code section 1.001')
26
+ 2021-09-26T18:14:29.933849+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] ↳ app/models/statute.rb:491:in `find_by_cite_case_insensitive'
27
+ 2021-09-26T18:14:29.937540+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Publication Load (1.1ms) SELECT "publications".* FROM "publications" WHERE "publications"."jurisdiction_id" = $1 AND "publications"."compilation_slug" = $2 LIMIT $3 [["jurisdiction_id", 206], ["compilation_slug", "statutes"], ["LIMIT", 1]]
28
+ 2021-09-26T18:14:29.937842+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] ↳ app/controllers/statutes_controller.rb:303:in `publication'
29
+ 2021-09-26T18:14:29.938542+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendering layout layouts/application.haml
30
+ 2021-09-26T18:14:29.938577+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendering statutes/leaf_node.haml within layouts/application
31
+ 2021-09-26T18:14:29.939858+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered statutes/leaf_node.haml within layouts/application (Duration: 1.2ms | Allocations: 149)
32
+ 2021-09-26T18:14:29.940074+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_description.haml (Duration: 0.0ms | Allocations: 10)
33
+ 2021-09-26T18:14:29.940669+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_favicon.haml (Duration: 0.4ms | Allocations: 303)
34
+ 2021-09-26T18:14:29.940924+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_structured_data_website.haml (Duration: 0.0ms | Allocations: 11)
35
+ 2021-09-26T18:14:29.941028+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_structured_data_organization.haml (Duration: 0.0ms | Allocations: 11)
36
+ 2021-09-26T18:14:29.941086+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_html_head.haml (Duration: 1.1ms | Allocations: 709)
37
+ 2021-09-26T18:14:29.942826+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Statute Load (1.1ms) SELECT "statutes".* FROM "statutes" WHERE "statutes"."id" = $1 LIMIT $2 [["id", 88374639], ["LIMIT", 1]]
38
+ 2021-09-26T18:14:29.943230+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] ↳ app/presenters/statute_presenter.rb:149:in `parent'
39
+ 2021-09-26T18:14:29.943596+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_body_tag.erb (Duration: 2.4ms | Allocations: 764)
40
+ 2021-09-26T18:14:29.944141+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_small_search_form.haml (Duration: 0.2ms | Allocations: 105)
41
+ 2021-09-26T18:14:29.944440+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_top_nav_bar.haml (Duration: 0.8ms | Allocations: 453)
42
+ 2021-09-26T18:14:29.944876+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_breadcrumbs.haml (Duration: 0.3ms | Allocations: 397)
43
+ 2021-09-26T18:14:29.945012+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_devise_alerts.haml (Duration: 0.1ms | Allocations: 25)
44
+ 2021-09-26T18:14:29.945171+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_citation.haml (Duration: 0.0ms | Allocations: 27)
45
+ 2021-09-26T18:14:29.945283+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_search_mark_toggle.haml (Duration: 0.0ms | Allocations: 13)
46
+ 2021-09-26T18:14:29.945498+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_ads.haml (Duration: 0.2ms | Allocations: 76)
47
+ 2021-09-26T18:14:29.945537+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_right_side_bar.haml (Duration: 0.5ms | Allocations: 296)
48
+ 2021-09-26T18:14:29.946102+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_footer_for_screen.haml (Duration: 0.4ms | Allocations: 524)
49
+ 2021-09-26T18:14:29.946243+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_footer_for_print.haml (Duration: 0.1ms | Allocations: 30)
50
+ 2021-09-26T18:14:29.946328+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_footer.haml (Duration: 0.7ms | Allocations: 677)
51
+ 2021-09-26T18:14:29.946526+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_analytics.haml (Duration: 0.0ms | Allocations: 14)
52
+ 2021-09-26T18:14:29.946609+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered application/_closing_body_tag.erb (Duration: 0.0ms | Allocations: 9)
53
+ 2021-09-26T18:14:29.946646+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Rendered layout layouts/application.haml (Duration: 8.1ms | Allocations: 4132)
54
+ 2021-09-26T18:14:29.946815+00:00 app[web.1]: [07e1adff-5df8-43d3-aab4-0e1d6b56b001] Completed 200 OK in 17ms (Views: 7.3ms | ActiveRecord: 3.7ms | Elasticsearch: 0.0ms | Allocations: 6414)
55
+ ```
56
+
57
+ ```
58
+ 2021-09-26T18:21:26.654003+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Started GET "/statutes/tex._fam._code_section_1.001" for 172.70.45.202 at 2021-09-26 18:21:26 +0000
59
+ 2021-09-26T18:21:26.656935+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Processing by StatutesController#show as HTML
60
+ 2021-09-26T18:21:26.656978+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Parameters: {"compilation"=>"statutes", "id"=>"tex._fam._code_section_1.001"}
61
+ 2021-09-26T18:21:26.661787+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Statute Load (1.5ms) SELECT "statutes".* FROM "statutes" WHERE (LOWER(citation) = 'tex. fam. code section 1.001')
62
+ 2021-09-26T18:21:26.662597+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] ↳ app/models/statute.rb:491:in `find_by_cite_case_insensitive'
63
+ 2021-09-26T18:21:26.670170+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Publication Load (1.3ms) SELECT "publications".* FROM "publications" WHERE "publications"."jurisdiction_id" = $1 AND "publications"."compilation_slug" = $2 LIMIT $3 [["jurisdiction_id", 206], ["compilation_slug", "statutes"], ["LIMIT", 1]]
64
+ 2021-09-26T18:21:26.670808+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] ↳ app/controllers/statutes_controller.rb:303:in `publication'
65
+ 2021-09-26T18:21:26.671936+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendering layout layouts/application.haml
66
+ 2021-09-26T18:21:26.671990+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendering statutes/leaf_node.haml within layouts/application
67
+ 2021-09-26T18:21:26.676444+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered statutes/leaf_node.haml within layouts/application (Duration: 1.8ms | Allocations: 149)
68
+ 2021-09-26T18:21:26.676446+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_description.haml (Duration: 0.1ms | Allocations: 10)
69
+ 2021-09-26T18:21:26.676446+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_favicon.haml (Duration: 0.5ms | Allocations: 247)
70
+ 2021-09-26T18:21:26.676446+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_structured_data_website.haml (Duration: 0.0ms | Allocations: 11)
71
+ 2021-09-26T18:21:26.676447+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_structured_data_organization.haml (Duration: 0.0ms | Allocations: 11)
72
+ 2021-09-26T18:21:26.676447+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_html_head.haml (Duration: 1.4ms | Allocations: 591)
73
+ 2021-09-26T18:21:26.677699+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Statute Load (1.3ms) SELECT "statutes".* FROM "statutes" WHERE "statutes"."id" = $1 LIMIT $2 [["id", 88374639], ["LIMIT", 1]]
74
+ 2021-09-26T18:21:26.678321+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] ↳ app/presenters/statute_presenter.rb:149:in `parent'
75
+ 2021-09-26T18:21:26.678955+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_body_tag.erb (Duration: 3.4ms | Allocations: 764)
76
+ 2021-09-26T18:21:26.679660+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_top_nav_bar.haml (Duration: 0.6ms | Allocations: 264)
77
+ 2021-09-26T18:21:26.680105+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_breadcrumbs.haml (Duration: 0.3ms | Allocations: 397)
78
+ 2021-09-26T18:21:26.680279+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_devise_alerts.haml (Duration: 0.1ms | Allocations: 25)
79
+ 2021-09-26T18:21:26.680500+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_citation.haml (Duration: 0.1ms | Allocations: 28)
80
+ 2021-09-26T18:21:26.680632+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_search_mark_toggle.haml (Duration: 0.0ms | Allocations: 13)
81
+ 2021-09-26T18:21:26.680935+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_ads.haml (Duration: 0.2ms | Allocations: 77)
82
+ 2021-09-26T18:21:26.680981+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_right_side_bar.haml (Duration: 0.6ms | Allocations: 298)
83
+ 2021-09-26T18:21:26.681199+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_analytics.haml (Duration: 0.1ms | Allocations: 14)
84
+ 2021-09-26T18:21:26.681307+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered application/_closing_body_tag.erb (Duration: 0.0ms | Allocations: 9)
85
+ 2021-09-26T18:21:26.681357+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Rendered layout layouts/application.haml (Duration: 9.4ms | Allocations: 3040)
86
+ 2021-09-26T18:21:26.681614+00:00 app[web.1]: [2058c55d-fc7f-4914-ac65-94a7862f1df1] Completed 200 OK in 24ms (Views: 8.6ms | ActiveRecord: 4.1ms | Elasticsearch: 0.0ms | Allocations: 5315)
17
87
  ```
18
88
 
19
- With AssetRam:
20
89
 
90
+ ### Production comparison test #2: https://texas.public.law/statutes/tex._fam._code_section_1.101
91
+
92
+ * 17% fewer Allocations (5306 vs. 6407)
93
+ * 1,101 allocations saved only by not rendering the footer views.
94
+ * 1ms slower
95
+
96
+ ```
97
+ 2021-09-26T18:01:39.440294+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Started GET "/statutes/tex._fam._code_section_1.101" for 172.70.45.216 at 2021-09-26 18:01:39 +0000
98
+ 2021-09-26T18:01:39.441510+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Processing by StatutesController#show as HTML
99
+ 2021-09-26T18:01:39.441555+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Parameters: {"compilation"=>"statutes", "id"=>"tex._fam._code_section_1.101"}
100
+ 2021-09-26T18:01:39.445556+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Statute Load (1.4ms) SELECT "statutes".* FROM "statutes" WHERE (LOWER(citation) = 'tex. fam. code section 1.101')
101
+ 2021-09-26T18:01:39.445960+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] ↳ app/models/statute.rb:491:in `find_by_cite_case_insensitive'
102
+ 2021-09-26T18:01:39.450228+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Publication Load (1.2ms) SELECT "publications".* FROM "publications" WHERE "publications"."jurisdiction_id" = $1 AND "publications"."compilation_slug" = $2 LIMIT $3 [["jurisdiction_id", 206], ["compilation_slug", "statutes"], ["LIMIT", 1]]
103
+ 2021-09-26T18:01:39.450595+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] ↳ app/controllers/statutes_controller.rb:303:in `publication'
104
+ 2021-09-26T18:01:39.451536+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendering layout layouts/application.haml
105
+ 2021-09-26T18:01:39.451577+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendering statutes/leaf_node.haml within layouts/application
106
+ 2021-09-26T18:01:39.453102+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered statutes/leaf_node.haml within layouts/application (Duration: 1.5ms | Allocations: 149)
107
+ 2021-09-26T18:01:39.453319+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_description.haml (Duration: 0.0ms | Allocations: 10)
108
+ 2021-09-26T18:01:39.454083+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_favicon.haml (Duration: 0.6ms | Allocations: 247)
109
+ 2021-09-26T18:01:39.454484+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_structured_data_website.haml (Duration: 0.1ms | Allocations: 11)
110
+ 2021-09-26T18:01:39.454638+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_structured_data_organization.haml (Duration: 0.0ms | Allocations: 11)
111
+ 2021-09-26T18:01:39.454743+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_html_head.haml (Duration: 1.5ms | Allocations: 591)
112
+ 2021-09-26T18:01:39.456713+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Statute Load (1.1ms) SELECT "statutes".* FROM "statutes" WHERE "statutes"."id" = $1 LIMIT $2 [["id", 88374639], ["LIMIT", 1]]
113
+ 2021-09-26T18:01:39.457251+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] ↳ app/presenters/statute_presenter.rb:149:in `parent'
114
+ 2021-09-26T18:01:39.457918+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_body_tag.erb (Duration: 3.0ms | Allocations: 764)
115
+ 2021-09-26T18:01:39.458795+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_top_nav_bar.haml (Duration: 0.7ms | Allocations: 264)
116
+ 2021-09-26T18:01:39.459195+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_breadcrumbs.haml (Duration: 0.3ms | Allocations: 397)
117
+ 2021-09-26T18:01:39.459348+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_devise_alerts.haml (Duration: 0.1ms | Allocations: 25)
118
+ 2021-09-26T18:01:39.459532+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_citation.haml (Duration: 0.1ms | Allocations: 27)
119
+ 2021-09-26T18:01:39.459629+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_search_mark_toggle.haml (Duration: 0.0ms | Allocations: 13)
120
+ 2021-09-26T18:01:39.459883+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_ads.haml (Duration: 0.2ms | Allocations: 76)
121
+ 2021-09-26T18:01:39.459936+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_right_side_bar.haml (Duration: 0.5ms | Allocations: 296)
122
+ 2021-09-26T18:01:39.460068+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_analytics.haml (Duration: 0.0ms | Allocations: 14)
123
+ 2021-09-26T18:01:39.460168+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered application/_closing_body_tag.erb (Duration: 0.0ms | Allocations: 9)
124
+ 2021-09-26T18:01:39.460207+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Rendered layout layouts/application.haml (Duration: 8.6ms | Allocations: 3038)
125
+ 2021-09-26T18:01:39.460447+00:00 app[web.1]: [b7aafc2c-103a-4800-ad5d-ec3a433bbf58] Completed 200 OK in 19ms (Views: 8.0ms | ActiveRecord: 3.6ms | Elasticsearch: 0.0ms | Allocations: 5306)
21
126
  ```
22
- Completed 200 OK in 11ms (Views: 5.1ms | ActiveRecord: 1.3ms | Allocations: 5208)
127
+
128
+ ```
129
+ 2021-09-26T18:06:54.091909+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Started GET "/statutes/tex._fam._code_section_1.101" for 172.70.45.192 at 2021-09-26 18:06:54 +0000
130
+ 2021-09-26T18:06:54.093016+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Processing by StatutesController#show as HTML
131
+ 2021-09-26T18:06:54.093035+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Parameters: {"compilation"=>"statutes", "id"=>"tex._fam._code_section_1.101"}
132
+ 2021-09-26T18:06:54.096923+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Statute Load (1.4ms) SELECT "statutes".* FROM "statutes" WHERE (LOWER(citation) = 'tex. fam. code section 1.101')
133
+ 2021-09-26T18:06:54.097253+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] ↳ app/models/statute.rb:491:in `find_by_cite_case_insensitive'
134
+ 2021-09-26T18:06:54.101086+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Publication Load (1.1ms) SELECT "publications".* FROM "publications" WHERE "publications"."jurisdiction_id" = $1 AND "publications"."compilation_slug" = $2 LIMIT $3 [["jurisdiction_id", 206], ["compilation_slug", "statutes"], ["LIMIT", 1]]
135
+ 2021-09-26T18:06:54.101391+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] ↳ app/controllers/statutes_controller.rb:303:in `publication'
136
+ 2021-09-26T18:06:54.102192+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendering layout layouts/application.haml
137
+ 2021-09-26T18:06:54.102243+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendering statutes/leaf_node.haml within layouts/application
138
+ 2021-09-26T18:06:54.103670+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered statutes/leaf_node.haml within layouts/application (Duration: 1.4ms | Allocations: 150)
139
+ 2021-09-26T18:06:54.103856+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_description.haml (Duration: 0.0ms | Allocations: 10)
140
+ 2021-09-26T18:06:54.104549+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_favicon.haml (Duration: 0.4ms | Allocations: 303)
141
+ 2021-09-26T18:06:54.104780+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_structured_data_website.haml (Duration: 0.0ms | Allocations: 11)
142
+ 2021-09-26T18:06:54.104865+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_structured_data_organization.haml (Duration: 0.0ms | Allocations: 11)
143
+ 2021-09-26T18:06:54.104919+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_html_head.haml (Duration: 1.1ms | Allocations: 709)
144
+ 2021-09-26T18:06:54.106775+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Statute Load (1.2ms) SELECT "statutes".* FROM "statutes" WHERE "statutes"."id" = $1 LIMIT $2 [["id", 88374639], ["LIMIT", 1]]
145
+ 2021-09-26T18:06:54.107110+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] ↳ app/presenters/statute_presenter.rb:149:in `parent'
146
+ 2021-09-26T18:06:54.107499+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_body_tag.erb (Duration: 2.5ms | Allocations: 764)
147
+ 2021-09-26T18:06:54.108000+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_small_search_form.haml (Duration: 0.1ms | Allocations: 105)
148
+ 2021-09-26T18:06:54.108352+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_top_nav_bar.haml (Duration: 0.8ms | Allocations: 453)
149
+ 2021-09-26T18:06:54.108794+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_breadcrumbs.haml (Duration: 0.3ms | Allocations: 397)
150
+ 2021-09-26T18:06:54.108943+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_devise_alerts.haml (Duration: 0.1ms | Allocations: 25)
151
+ 2021-09-26T18:06:54.109118+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_citation.haml (Duration: 0.0ms | Allocations: 27)
152
+ 2021-09-26T18:06:54.109211+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_search_mark_toggle.haml (Duration: 0.0ms | Allocations: 13)
153
+ 2021-09-26T18:06:54.109473+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_ads.haml (Duration: 0.2ms | Allocations: 76)
154
+ 2021-09-26T18:06:54.109530+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_right_side_bar.haml (Duration: 0.5ms | Allocations: 296)
155
+ 2021-09-26T18:06:54.110122+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_footer_for_screen.haml (Duration: 0.5ms | Allocations: 524)
156
+ 2021-09-26T18:06:54.110278+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_footer_for_print.haml (Duration: 0.1ms | Allocations: 30)
157
+ 2021-09-26T18:06:54.110321+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_footer.haml (Duration: 0.7ms | Allocations: 677)
158
+ 2021-09-26T18:06:54.110586+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_analytics.haml (Duration: 0.1ms | Allocations: 14)
159
+ 2021-09-26T18:06:54.110704+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered application/_closing_body_tag.erb (Duration: 0.0ms | Allocations: 9)
160
+ 2021-09-26T18:06:54.110745+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Rendered layout layouts/application.haml (Duration: 8.5ms | Allocations: 4133)
161
+ 2021-09-26T18:06:54.110920+00:00 app[web.1]: [2888c0c9-6d62-46bf-96f7-b8507b6101d3] Completed 200 OK in 18ms (Views: 7.7ms | ActiveRecord: 3.8ms | Elasticsearch: 0.0ms | Allocations: 6407)
23
162
  ```
24
163
 
25
164
 
165
+
26
166
  ## Usage
27
167
 
28
168
  Wrap every asset helper call with `#cache`, like this:
@@ -39,13 +179,12 @@ Wrap every asset helper call with `#cache`, like this:
39
179
  <%= AssetRam::Helper.cache { favicon_link_tag('favicon/favicon.ico', rel: 'icon') } %>
40
180
  ```
41
181
 
42
- After booting up, messages like these will appear _once_ in the log. They show the
43
- full cache key.
182
+ After booting up, a message like this will appear _once_ in the log when the asset link
183
+ is generated. It shows the full cache key so we can see what it's caching. This is the line
184
+ of code that, without AssetRam, would be exectued on every request.
44
185
 
45
186
  ```
46
- Caching ["/Users/robb/src/PublicLaw/public-law-website/app/views/application/_html_head.haml", 16, "texas"]
47
187
  Caching ["/Users/robb/src/PublicLaw/public-law-website/app/views/application/_favicon.haml", 8]
48
- Caching ["/Users/robb/src/PublicLaw/public-law-website/app/views/application/_favicon.haml", 11]
49
188
  ```
50
189
 
51
190
  I use it in my footer for social icons as well: (HAML syntax)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AssetRam
4
- VERSION = "0.2.0"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/asset_ram.rb CHANGED
@@ -27,18 +27,23 @@ module AssetRam
27
27
  ##
28
28
  # Our own asset helper which memoizes Rails' asset helper calls.
29
29
  class Helper
30
-
31
30
  @@_cache = {}
32
31
 
33
- def self.cache(key: '', &blk)
34
- return yield if ENV['ASSET_RAM_DISABLE']
35
32
 
33
+ def self.cache(key: '', &blk)
36
34
  cache_key = blk.source_location
37
35
  cache_key << key if key.present?
38
36
 
37
+ cache_by_key(cache_key, &blk)
38
+ end
39
+
40
+
41
+ def self.cache_by_key(cache_key, &blk)
42
+ return yield if ENV['ASSET_RAM_DISABLE']
43
+
39
44
  if !@@_cache.has_key?(cache_key)
40
- # Using WARN level because it should only be output
41
- # once during any Rails run. If its output multiple
45
+ # Using WARN level because it should only output
46
+ # once during any Rails run. If it's output multiple
42
47
  # times, then caching isn't working correctly.
43
48
  Rails.logger.warn("Caching #{cache_key}")
44
49
  @@_cache[cache_key] = yield
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_ram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-26 00:00:00.000000000 Z
11
+ date: 2022-08-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
- rubygems_version: 3.2.28
52
+ rubygems_version: 3.3.11
53
53
  signing_key:
54
54
  specification_version: 4
55
55
  summary: Improves Rails performance by caching asset path calculations