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.4k
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
760
Ruby 3.0 JIT on Rails
k0kubun
9
9.1k
Other Decks in Programming
See All in Programming
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
110
Outline View in SwiftUI
1024jp
1
340
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Functional Event Sourcing using Sekiban
tomohisa
0
100
Ethereum_.pdf
nekomatu
0
470
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
900
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.2k
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
250
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
flutterkaigi_2024.pdf
kyoheig3
0
150
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Designing for humans not robots
tammielis
250
25k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
110
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Six Lessons from altMBA
skipperchong
27
3.5k
It's Worth the Effort
3n
183
27k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
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ͷੜίετʹؾΛ͚ͭΑ͏