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.6k
YJIT: Dive into Ruby's JIT compiler written in Rust / Rust.Tokyo 2022
k0kubun
1
2.1k
Towards Ruby 4 JIT / RubyKaigi 2022
k0kubun
3
11k
Optimizing Production Performance with MRI JIT / RubyConf 2021
k0kubun
1
430
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
790
Ruby 3.0 JIT on Rails
k0kubun
9
9.2k
Other Decks in Programming
See All in Programming
XStateを用いた堅牢なReact Components設計~複雑なClient Stateをシンプルに~ @React Tokyo ミートアップ #2
kfurusho
1
940
PHPカンファレンス名古屋2025 タスク分解の試行錯誤〜レビュー負荷を下げるために〜
soichi
1
560
Multi Step Form, Decentralized Autonomous Organization
pumpkiinbell
1
800
Formの複雑さに立ち向かう
bmthd
1
890
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
130
2024年のWebフロントエンドのふりかえりと2025年
sakito
3
260
.NET Frameworkでも汎用ホストが使いたい!
tomokusaba
0
170
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
53
18k
CI改善もDatadogとともに
taumu
0
170
『GO』アプリ バックエンドサーバのコスト削減
mot_techtalk
0
150
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
180
プログラミング言語学習のススメ / why-do-i-learn-programming-language
yashi8484
0
140
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
46
2.3k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
4
350
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
630
Rails Girls Zürich Keynote
gr2m
94
13k
Agile that works and the tools we love
rasmusluckow
328
21k
How to train your dragon (web standard)
notwaldorf
91
5.8k
4 Signs Your Business is Dying
shpigford
182
22k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
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ͷੜίετʹؾΛ͚ͭΑ͏