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
12k
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
410
Why Ruby's JIT was slow / RubyKaigi Takeout 2021
k0kubun
3
1.8k
数時間かかる週一リリースを毎日何度も爆速でできるようにするまで / 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
似たもの同士のPerlとPHP
uzulla
1
110
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
1
1.6k
talk-with-local-llm-with-web-streams-api
kbaba1001
0
160
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
140
Refactor your code - refactor yourself
xosofox
1
200
Develop iOS apps with Neovim / vimconf_2024
uhooi
1
330
暇に任せてProxmoxコンソール 作ってみました
karugamo
1
500
useSyncExternalStoreを使いまくる
ssssota
4
840
Missing parts when designing and implementing Android UI
ericksli
0
400
StarlingMonkeyを触ってみた話 - 2024冬
syumai
2
220
DevTools extensions で 独自の DevTool を開発する | FlutterKaigi 2024
kokiyoshida
0
460
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1k
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
160
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
It's Worth the Effort
3n
183
27k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
BBQ
matthewcrist
85
9.3k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
KATA
mclloyd
29
14k
Building Applications with DynamoDB
mza
91
6.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
490
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ͷੜίετʹؾΛ͚ͭΑ͏