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
1k
ハマったところ 表参道.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
690
mastodon
futoase
0
110
susumekata
futoase
1
700
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
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
160
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
140
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
170
組織に自動テストを書く文化を根付かせる戦略(2024冬版) / Building Automated Test Culture 2024 Winter Edition
twada
PRO
13
3.7k
権威ドキュメントで振り返る2024 #年忘れセキュリティ2024
hirotomotaguchi
2
740
フロントエンド設計にモブ設計を導入してみた / 20241212_cloudsign_TechFrontMeetup
bengo4com
0
1.9k
統計データで2024年の クラウド・インフラ動向を眺める
ysknsid25
2
840
20241214_WACATE2024冬_テスト設計技法をチョット俯瞰してみよう
kzsuzuki
3
450
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
210
podman_update_2024-12
orimanabu
1
270
コンテナセキュリティのためのLandlock入門
nullpo_head
2
320
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
3
2.3k
Featured
See All Featured
Bash Introduction
62gerente
608
210k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Building Applications with DynamoDB
mza
91
6.1k
Become a Pro
speakerdeck
PRO
26
5k
KATA
mclloyd
29
14k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
How to Ace a Technical Interview
jacobian
276
23k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Designing for humans not robots
tammielis
250
25k
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