Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
My patches for Rails 5
Search
Takashi Kokubun
May 29, 2016
Programming
5
6.2k
My patches for Rails 5
東急Ruby会議10 LT #tqrk10
Takashi Kokubun
May 29, 2016
Tweet
Share
More Decks by Takashi Kokubun
See All by Takashi Kokubun
YJIT Makes Rails 1.7x faster / RubyKaigi 2024
k0kubun
7
13k
Ruby JIT Hacking Guide / RubyKaigi 2023
k0kubun
2
9.5k
YJIT: Dive into Ruby's JIT compiler written in Rust / Rust.Tokyo 2022
k0kubun
1
2k
Towards Ruby 4 JIT / RubyKaigi 2022
k0kubun
3
11k
Optimizing Production Performance with MRI JIT / RubyConf 2021
k0kubun
1
420
Why Ruby's JIT was slow / RubyKaigi Takeout 2021
k0kubun
3
1.9k
数時間かかる週一リリースを毎日何度も爆速でできるようにするまで / CI/CD Conference 2021
k0kubun
21
14k
Ruby 3 JIT's roadmap / RubyConf China 2020
k0kubun
0
770
Ruby 3.0 JIT on Rails
k0kubun
9
9.1k
Other Decks in Programming
See All in Programming
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
150
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
130
선언형 UI에서의 상태관리
l2hyunwoo
0
200
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
200
nekko cloudにおけるProxmox VE利用事例
irumaru
3
460
ドメインイベント増えすぎ問題
h0r15h0
2
430
命名をリントする
chiroruxx
1
450
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
360
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
160
return文におけるstd::moveについて
onihusube
1
1.3k
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
340
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Why Our Code Smells
bkeepers
PRO
335
57k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
910
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Side Projects
sachag
452
42k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Building Your Own Lightsaber
phodgson
103
6.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Designing for humans not robots
tammielis
250
25k
GitHub's CSS Performance
jonrohan
1031
460k
Speed Design
sergeychernyshev
25
680
Transcript
My patches for Rails 5 @k0kubun TokyuRubyձٞ10
ࣗݾհ • Twitter, GitHub: @k0kubun • Cookpad • ٕज़෦։ൃج൫άϧʔϓ •
RailsͷϑΝϯ • ίϛοτ7
ࠓ͢͜ͱ • ͕ Rails 5.0 ʹ͍ΕͨҎԼͷύονʹؔͯ͠ࢥ͏ ͜ͱΛ͠·͢ • #22722 Use
CGI.escapeHTML for html escape • #18109 Allow joins to be unscoped • #22125 Alias left_joins to left_outer_joins
Use CGI.escapeHTML for html escape https://github.com/rails/rails/pull/22722
#22722 Use CGI.escapeHTML for html escape
#22722 Use CGI.escapeHTML for html escape • erbͷHTMLΤεέʔϓʹgsubͷݺͼग़͠Ͱ ͳ͘ CGI.escapeHTML
Λ͏Α͏ʹ͢Δౕ • Ruby 2.3 Ͱ CGI.escapeHTML ΛߴԽͨ͠
CGI.escapeHTMLͷߴԽύον
• ݩ୯ͳΔ gsub(/[&"'><]/, { '&' => '&', .. }) •
͜ΕΛ͔ͳΓ۪ʹCʹॻ͖͚ͨͩ͠ • UTF-8ؚΉASCIIޓͷΤϯίʔσΟϯάͰ࠷େ 7ഒߴԽ • ext/cgi/escape ര CGI.escapeHTMLͷߴԽύον
ͳͥHTMLΤεέʔϓΛߴԽ ͔ͨ͠ • RailsͷerbͷϨϯμϦϯάͰHTMLΤεέʔϓ͕Ϙ τϧωοΫͩͬͨ͠ɺଞʹ͘͠Α͏͕ͳ͍͔Β
Ͳͷ͘Β͍มΘ͔ͬͨ • લఏࣝ: String࿈݁ͷݱࡏͷੑೳൺֱ TMJNͷDPNQJMFECFODIͷ)5.-Τεέʔϓ༗ޮ൛ JT
IBNMJU W TMJN W GBNM W FSVCJT W IBNM WCFUB https://travis-ci.org/k0kubun/hamlit/jobs/131694989
Ͳͷ͘Β͍มΘ͔ͬͨ • ActionViewͰͷݩʑͷੑೳൺֱ https://gist.github.com/k0kubun/e9363d8359d9a9604c55bd23fb28c64d લͷϖʔδͷౕͷ"DUJPO7JFXԽ൛ FSCͷ$(*FTDBQF)5.-Խͳ͠ JT
IBNMJU W TMJN W GBNM W "75FNQMBUF )FMQFST&SVCJT IBNM WCFUB
Ͳͷ͘Β͍มΘ͔ͬͨ • ActionViewͰͷerbͷCGI.escapeHTMLԽͷޮՌ https://gist.github.com/k0kubun/3ea0c0dba78ac2e832c8fbe5a104d04b લͷϖʔδͷౕͷ"DUJPO7JFXԽ൛ FSCͷ$(*FTDBQF)5.-Խ͋Γ JT
IBNMJU W TMJN W GBNM W "75FNQMBUF )FMQFST&SVCJT IBNM WCFUB
RailsͰ࠷ͷςϯϓϨʔτΤϯδϯ • Hamlit ͔ σϑΥϧτͷ ActionView::Template::Handlers::Erubis • Ͳౕ͕ͬͪͨ͘͠ͳͷͰͲͬͪͬͯ ͘Ε͍͍ͯͰ͢
Allow joins to be unscoped https://github.com/rails/rails/pull/18109
#18109 Allow joins to be unscoped
#18109 Allow joins to be unscoped • (join͢Δ)includes, eager_load, joins
Ͱ unscopedΛͬͯ default_scope ͕֎ͤΔΑ ͏ʹͳΔ • 2͝͠ͷϚʔδ
default_scopeͷҋ • Ͳ͏ͬͨΒdefault_scopeͷόάमਖ਼ΛϚʔδ ͯ͠Β͑Δ͔૬ஊͯ͠Έͨ
default_scopeͷҋ • default_scopeʹࢥ͍ೖΕͷ͋Δίϛολʔ͕ ͍ͳ͍ͷͰ͏͖Ͱͳ͍
• ࣮ࡍͣͬͱϚʔδ͞Εͳ͔ͬͨ default_scopeͷҋ ↑ݴٴͯ͠Δissue͕ผͷํ๏Ͱղܾ͞ΕͨͷͰηϧϑΫϩʔζ
default_scopeͷҋ • ผͷϓϧϦͰdefault_scopeʹݴٴ͠ͳ͍Α ͏ʹͨ͠ΒϚʔδ͞Εͨ
default_scope͕֎ͤͳ͍ྫ • ͖ͬ͞ͷύον͕Ϛʔδ͞Εͯͳ͍ͷͰɺ
default_scope͕֎ͤͳ͍ྫ • preloadͯ͠Δ͔Ͳ͏͔Ͱ݁Ռ͕มΘΔ
Rails 5 ʹΔdefault_scopeͷόά • preload(join͠ͳ͍)includes default_scope͕֎ͤͳ͍
Rails 5 ʹΔdefault_scopeͷόά • Ͱࢿྉ࡞ͬͯͨΒͬͺͬͯཉ͘͠ͳͬ ͨͷͰࠓϓϧϦग़͠͠·ͨ͠
Alias left_joins to left_outer_joins https://github.com/rails/rails/pull/22125
#22125 Alias left_joins to left_outer_joins
#22125 Alias left_joins to left_outer_joins • left_outer_joins ͷΤΠϦΞε left_joins ΛՃ
͢Δ͚ͩ • ͨΓલ͚ͩͲҒ͍ͷͷϓϧϦͰͳ͘ left_outer_joins ΛՃ͢ΔํͷϓϧϦ • ·͋Ͱleft_outer_joinsͱ͔͗ͯ͢Θͳ ͍ΑͶ
ͦͦͳΜͰ left_outer_joins ͕ͦΜͳʹཉ͔͔ͬͨ͠ • ߜΓࠐΈͨΊͷLEFT OUTER JOINΛੜSQLΛ Θͣʹॻͨ͘ΊʹincludesΛ͏ਓ͕͍Δ • eager
loadͯ͠͏Θ͚Ͱͳ͍Ϩίʔυͷ AR::BaseΠϯελϯε͕େྔʹ࡞ΒΕ͍ • ͦ͏͍͏༻్ͷϝιου͡Όͳ͍ͱϨϏϡʔ ͢ΔͱΠϯλʔωοτΛࠜڌʹൃ͞ΕΔ
ͦͦͳΜͰ left_outer_joins ͕ͦΜͳʹཉ͔͔ͬͨ͠
ͦͦͳΜͰ left_outer_joins ͕ͦΜͳʹཉ͔͔ͬͨ͠ • eager loading͕ෆཁͳΒRails 4ҎԼͰੜΫ ΤϦॻ͍ͨํ͕Ϛγͱࢥ͍ͬͯ·͢ • Rails
5Ͱͬͱͦ͏͠ͳͯ͘Α͘ͳΔ
༨ஊ: ͦͷincludesຊʹ͘ ͳΔ͔֬ೝͯ͠Δʁ • N+1௵ͯ͠ΫΤϦ͚ͩͯ͘͠τʔλϧͰ͘ͳΔͱ ݶΒͳ͍ • ಛʹhas_many associationΛeager loadingͯ͠AR::Base
͕ಉ࣌ʹେྔʹ࡞ΒΕΔ߹ • ʮincludesͯ͠N+1ͳ͘͠·ͨ͠ʂʯΈ͍ͨͳϓϧϦɺ લޙͷࠩΛషͬͯ΄͍͠ • rails sͷϩάݟΔ͚ͩͰΘ͔Δ
༨ஊ: ͦͦԶincludesࣗମ ͕ݏ͍ͩ • ͏ਓͷؾ͕࣋ͪશ͘Θ͔Βͳ͍ • includesΛݟ͚ͨͩͰͲ͏͍͏ڍಈΛ͢Δͷ͔༧ଌͰ͖ͣ Մಡੑ͕͍ • JOIN͢ΔͭΓͳ͍ॴͰJOIN͞ΕͨΒΤϥʔʹͳͬͯཉ͍͠
• includes(:foo).references(:foo)ͱ͔includes(:foo).joins(:foo) Έ͍ͨͳͳॻ͖ํ͕ؾʹͳΔ • eager_load(:foo)Ͱ͍͍͡ΌΜ
༨ஊ: ͦͦԶincludesࣗମ ͕ݏ͍ͩ • Q: Recipe.includes(:steps).foo_scope.to_a stepsͱJOIN͢Δ͔?
༨ஊ: ͦͦԶincludesࣗମ ͕ݏ͍ͩ • Q: Recipe.includes(:steps).foo_scope.to_a stepsͱJOIN͢Δ͔? • A: Θ͔Βͳ͍
• foo_scopeͷఆٛʹΑΔ
·ͱΊ • Ruby 2.3 ͱ Rails 5.0 Λ͏ͱerb͕͘ͳΔ • default_scopeόάͬͯΔ͠ϝϯς͞Εͳ͍
• includesͷ͍ํΛݟͯ͠ཉ͍͠ • AR::BaseͷੜίετʹؾΛ͚ͭΑ͏