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
ハマったところ 表参道.rb #44 / into a problem
Search
Keiji Matsuzaki
March 07, 2019
Technology
0
990
ハマったところ 表参道.rb #44 / into a problem
Railsアプリ運用時にハマったときの体験です
Keiji Matsuzaki
March 07, 2019
Tweet
Share
More Decks by Keiji Matsuzaki
See All by Keiji Matsuzaki
note engineer meetup #3 インフラの現状 / note engineer meetup #3 infra
futoase
4
1.1k
note meetup #2 Electronを利用した10面ディスプレイの操作 / Controll of gaienmae display
futoase
0
680
mastodon
futoase
0
110
susumekata
futoase
1
690
freee-wacul-web-app-lt-one
futoase
0
1.8k
Engineer All Hands #5 (freee) 「インフラ」
futoase
0
470
soracom-go
futoase
0
340
AWS Summit Tokyo 2015 freee
futoase
19
20k
freee-shigure-matsuri-20150321
futoase
8
2.1k
Other Decks in Technology
See All in Technology
TypeScript、上達の瞬間
sadnessojisan
46
13k
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.8k
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.1k
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
170
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
170
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
SSMRunbook作成の勘所_20241120
koichiotomo
2
130
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
750
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
150
元旅行会社の情シス部員が教えるおすすめなre:Inventへの行き方 / What is the most efficient way to re:Invent
naospon
2
340
Featured
See All Featured
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Side Projects
sachag
452
42k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
The Invisible Side of Design
smashingmag
298
50k
Teambox: Starting and Learning
jrom
133
8.8k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Statistics for Hackers
jakevdp
796
220k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Transcript
ϋϚͬͨͱ͜Ζ දࢀಓ.rb #44 2019/3/7
ࣗݾհ • Piece of Cake, Inc. • দ࡚ ܒ࣏ (·͖ͭ͟
͚͍͡) • αʔόαΠυ݉ΠϯϑϥΤϯδχΞ • 20191݄͔Β
RubyRailsͷਂ ͖·ͤΜm(_ _)m
ϋϚͬͨࣄྫͷ͝հ
uniq
uniq • ͖͔͚ͬRails 4.2 -> 5.1ͷΞοϓάϨʔυ͕࠷ॳͷࣄ • deprecated 5.0 ->
5.1ΑΓ • distinctʹॻ͖͑Δඞཁ͕͋Δ • uniqΛ͋Δఔݕࡧ͍͕ͯͨ͠ɺͱ͋ΔՕॴͰॻ͖͑ ࿙Ε͕͋ͬͨ
uniq • ActiveRecord::RelationʹͯuniqΛ͏ͱSELECT DISTINCT… ͱ DISTINCTจʹม͑ͯ͘ΕΔػೳ • Rails 5.1͔ΒɺActiveRecord::RelationEnumerableΛ includeͯ͠ରԠ͢ΔΑ͏ʹͳͬͨͷͰɺArrayΛฦ͢
uniq • ى͖ͨ -> SELECT id FROM… ʹͯऔಘͨ͠IDΛݩʹ ϨίʔυΛݕࡧ͢ΔΫΤϦ͕͋ͬͨ •
uniqͰɺDISTINCT͕ޮ͍ͨͱ͖ɺidͷ͕ߜΓࠐ·Εͯ ͍ͨ
uniq • طଘͷΫΤϦn✕n✕n…(ੵ)ɺDISTINCT͕༗ޮʹͳΒͳ ͍ͱऔಘ͢ΔϨίʔυ͕૿͑ΔΑ͏ʹͳ͍ͬͯͨ • EXPLAINͰ࣮ߦͯ͠ɺΫΤϦύϑΥʔϚϯε݁ՌΛݟͯ ͋ͱͰڍಈΛ֬ೝͰ͖ͨ
uniq • Rails 5.1͔Βɺuniqͦͷͷͷϝιου׆༻Ͱ͖Δͷͩ ͕ɺArrayͱͯ͠ฦͬͯ͘Δ • Rails 5.0 -> 5.1ΞοϓάϨʔυ࣌ʹϨίʔυͷগͳ͍
ڥͰಈ࡞֬ೝΛ͢ΔͨΊɺಈ࡞ʹؔͯ͠ΈΒΕͣ
uniq • Production deployޙɺҰ෦Controller#ActionͷϨεϙϯε λΠϜ͕େ͖͘ͳΔ • unicornͷϓϩηε͕Ԡ͠ͳ͘ͳΔ • ଞͷunicornϓϩηε͕ଞͷϦΫΤετΛॲཧ͠Α͏ͱ͠ ͯɺಉ͡Controller#ActionͷॲཧΛ࣮ߦͯ͠͠·͏
uniq • ͱͳΔController#ActionΛ͍ͬͯ͘ͱɺuniqͱॻ͔ Ε͍ͯͨɻ • uniq͔Βdistinctʹஔ͖͑Δͱ͕ࢭΜͩ
deprecatedͱܯࠂ͞Εͨޙ Ҿ͖ଓ͖͑Δϝιουʹ ҙ͠Α͏
Rails Update࣌ʹ Upgrade GuideΛݟΑ͏
ଞ (աڈͷܦݧ)
ଞ (աڈͷܦݧ) • INDEXΛࢥͬͨΑ͏ʹͬͯ͘Ε͍ͯͳ͍͜ͱ͕Θ͔ͬͨ ͷͰɺFORCE INDEXΛ͏Α͏ʹվળ͢Δ • SELECT … FOR
UPDATE Λൃߦதɺ͏͔ͬΓtransaction blockʹ ଞαʔϏε ͷAPIΞΫηεΛߦ͏ॲཧΛೖΕͯ ͠·͏ • ଞαʔϏεͷϦΫΤετॲཧʹࣦഊ͠ߦLOCKΛѲͬͨ· ·ʹͳΓঃʑʹϦΫΤετʹ٧·͍ͬͯ͘ͳͲ
ऴΘΓ
ࢀߟ • ActiveRecord::Relation distinct method (Rails 4.2) • https://github.com/rails/rails/blob/v4.2.11/activerecord/ lib/active_record/relation/query_methods.rb#L776
• ActiveRecord::Relation (Rails 5.1) -> include Enumerable • https://github.com/rails/rails/blob/v5.1.6.1/activerecord/ lib/active_record/relation.rb
ࢀߟ • ΠϯσοΫεώϯτͷߏจ (FORCE INDEX) • https://dev.mysql.com/doc/refman/5.6/ja/index-hints.html • ϩοΫಡΈऔΓ (SELECT
… FOR UPDATE) • https://dev.mysql.com/doc/refman/5.6/ja/innodb-locking- reads.html
ࢀߟ • Rails Upgrade Guide (ຊޠ൛) • https://railsguides.jp/upgrading_ruby_on_rails.html