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
19k
freee-shigure-matsuri-20150321
futoase
8
2.1k
Other Decks in Technology
See All in Technology
生成AIと知識グラフの相互利用に基づく文書解析
koujikozaki
1
130
AWS CDKでデータリストアの運用、どのように設計する?~Aurora・EFSの実践事例を紹介~/aws-cdk-data-restore-aurora-efs
mhrtech
4
630
物価高なラスベガスでの過ごし方
zakky
0
350
「最高のチューニング」をしないために / hack@delta 24.10
fujiwara3
21
3.4k
AWS re:Inventを徹底的に楽しむためのTips / Tips for thoroughly enjoying AWS re:Invent
yuj1osm
1
540
ガバメントクラウド単独利用方式におけるIaC活用
techniczna
3
260
一休.comレストランにおけるRustの活用
kymmt90
3
580
生成AIとAWS CDKで実現! 自社ブログレビューの効率化
ymae
2
320
신뢰할 수 있는 AI 검색 엔진을 만들기 위한 Liner의 여정
huffon
0
260
新R25、乃木坂46 Mobileなどのファンビジネスを支えるマルチテナンシーなプラットフォームの全体像 / cam-multi-cloud
cyberagentdevelopers
PRO
1
130
話題のGraphRAG、その可能性と課題を理解する
hide212131
4
1.4k
プロダクト成長に対応するプラットフォーム戦略:Authleteによる共通認証基盤の移行事例 / Building an authentication platform using Authlete and AWS
kakehashi
1
150
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
13
1.9k
Facilitating Awesome Meetings
lara
49
6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.1k
The Art of Programming - Codeland 2020
erikaheidi
51
13k
Music & Morning Musume
bryan
46
6.1k
RailsConf 2023
tenderlove
29
880
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Code Reviewing Like a Champion
maltzj
519
39k
Scaling GitHub
holman
458
140k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
7
150
Become a Pro
speakerdeck
PRO
24
5k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
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