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
Ruby JIT Hacking Guide / RubyKaigi 2023
k0kubun
2
9k
YJIT: Dive into Ruby's JIT compiler written in Rust / Rust.Tokyo 2022
k0kubun
1
1.8k
Towards Ruby 4 JIT / RubyKaigi 2022
k0kubun
3
10k
Optimizing Production Performance with MRI JIT / RubyConf 2021
k0kubun
1
350
Why Ruby's JIT was slow / RubyKaigi Takeout 2021
k0kubun
3
1.7k
数時間かかる週一リリースを毎日何度も爆速でできるようにするまで / CI/CD Conference 2021
k0kubun
21
14k
Ruby 3 JIT's roadmap / RubyConf China 2020
k0kubun
0
670
Ruby 3.0 JIT on Rails
k0kubun
9
8.8k
JIT ロードマップ / Ruby 3 さみっと
k0kubun
2
1.2k
Other Decks in Programming
See All in Programming
WebGLで始める コンピュータグラフィックス入門
heller77
0
340
CDKコントリビュートの最初の壁を越えよう! -簡単issueの見つけ方-
badmintoncryer
3
350
初心者のためのRubyKaigi入門/RubyKaigi Introduction
a_matsuda
10
1.7k
Balkan Ruby 2024 — How and why to run SQLite on Rails in production
fractaledmind
0
110
Exploring the Implementation of “t.Run”, “t.Parallel”, and “t.Cleanup”
akarin
1
140
Site Reliability Engineering for GMO
pyama86
9
1.1k
GraphQLサーバの構成要素を整理する #ハッカー鮨 #tsukijigraphql / graphql server technology selection
izumin5210
4
920
Open standards for building event-driven applications in the cloud
meteatamel
0
190
Ruby Pattern Matching
bkuhlmann
0
930
Sheets API使ってみた
toshi0383
2
170
Deep Dive into React Stream/Serialize
mugi_uno
3
760
効率化に挑戦してみたらモバイル開発が少し快適になった話
ryunakayama
0
140
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
26
2.3k
Become a Pro
speakerdeck
PRO
13
4.6k
In The Pink: A Labor of Love
frogandcode
138
21k
BBQ
matthewcrist
80
8.8k
5 minutes of I Can Smell Your CMS
philhawksworth
199
19k
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
Web Components: a chance to create the future
zenorocha
306
41k
We Have a Design System, Now What?
morganepeng
43
6.8k
Bash Introduction
62gerente
605
210k
Building Adaptive Systems
keathley
32
1.9k
The Pragmatic Product Professional
lauravandoore
26
5.8k
Git: the NoSQL Database
bkeepers
PRO
423
63k
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ͷੜίετʹؾΛ͚ͭΑ͏