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
710
mastodon
futoase
0
110
susumekata
futoase
1
710
freee-wacul-web-app-lt-one
futoase
0
1.8k
Engineer All Hands #5 (freee) 「インフラ」
futoase
0
470
soracom-go
futoase
0
350
AWS Summit Tokyo 2015 freee
futoase
19
20k
freee-shigure-matsuri-20150321
futoase
8
2.1k
Other Decks in Technology
See All in Technology
あなたはJVMの気持ちを理解できるか?
skrb
5
2k
プロダクト価値を引き上げる、「課題の再定義」という習慣
moeka__c
0
210
BLEAでAWSアカウントのセキュリティレベルを向上させよう
koheiyoshikawa
0
140
GitLab SelfManagedをCodePipelineのソースに設定する/SetGitLabSelfManagedtoCodePipeline
norihiroishiyama
1
120
ソフトウェアアーキテクトのための意思決定術: Software Architecture and Decision-Making
snoozer05
PRO
17
4k
アクセシブルなマークアップの上に成り立つユーザーファーストなドロップダウンメニューの実装 / 20250127_cloudsign_User1st_FE
bengo4com
2
1.2k
DevSecOps入門:Security Development Lifecycleによる開発プロセスのセキュリティ強化
yuriemori
0
240
Agentic AI時代のプロダクトマネジメントことはじめ〜仮説検証編〜
masakazu178
3
410
さいきょうのアーキテクチャを生み出すセンスメイキング
jgeem
0
270
MCP server を作って Claude Desktop アプリから kintone へアクセスすると楽しい
r3_yamauchi
PRO
1
120
[2024年10月版] Notebook 2.0のご紹介 / Notebook2.0
databricksjapan
0
1.6k
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
18k
Featured
See All Featured
Building Your Own Lightsaber
phodgson
104
6.2k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
52k
The Pragmatic Product Professional
lauravandoore
32
6.4k
Why Our Code Smells
bkeepers
PRO
335
57k
A Tale of Four Properties
chriscoyier
157
23k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
39
1.9k
Designing Experiences People Love
moore
139
23k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
220
Practical Orchestrator
shlominoach
186
10k
Rails Girls Zürich Keynote
gr2m
94
13k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.8k
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