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
700
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
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
新しいスケーリング則と学習理論
taiji_suzuki
10
3.8k
GoogleのAIエージェント論 Authors: Julia Wiesinger, Patrick Marlow and Vladimir Vuskovic
customercloud
PRO
0
130
Copilotの力を実感!3ヶ月間の生成AI研修の試行錯誤&成功事例をご紹介。果たして得たものとは・・?
ktc_shiori
0
340
re:Invent2024 KeynoteのAmazon Q Developer考察
yusukeshimizu
1
140
EMConf JP の楽しみ方 / How to enjoy EMConf JP
pauli
2
150
30分でわかる「リスクから学ぶKubernetesコンテナセキュリティ」/30min-k8s-container-sec
mochizuki875
3
440
GeometryReaderやスクロールを用いた表現と紐解き方
fumiyasac0921
0
100
完全自律型AIエージェントとAgentic Workflow〜ワークフロー構築という現実解
pharma_x_tech
0
330
Oracle Exadata Database Service(Dedicated Infrastructure):サービス概要のご紹介
oracle4engineer
PRO
0
12k
【JAWS-UG大阪 reInvent reCap LT大会 サンバが始まったら強制終了】“1分”で初めてのソロ参戦reInventを数字で振り返りながら反省する
ttelltte
0
130
DMMブックスへのTipKit導入
ttyi2
1
100
Cloudflareで実現する AIエージェント ワークフロー基盤
kmd09
0
290
Featured
See All Featured
Building Your Own Lightsaber
phodgson
104
6.2k
Adopting Sorbet at Scale
ufuk
74
9.2k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Faster Mobile Websites
deanohume
305
30k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
173
51k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
570
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
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