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
DB呼び出し回数を減らしてコア機能を高速化した話
Search
Tasuku Nakagawa
April 09, 2024
0
240
DB呼び出し回数を減らしてコア機能を高速化した話
Tasuku Nakagawa
April 09, 2024
Tweet
Share
More Decks by Tasuku Nakagawa
See All by Tasuku Nakagawa
withContextってスレッド切り替え以外にも使えるって知ってた?
t45k
3
2k
R2DBCを導入しようとした話
t45k
0
350
コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
t45k
0
88
Featured
See All Featured
Fireside Chat
paigeccino
34
3.1k
Six Lessons from altMBA
skipperchong
27
3.5k
Speed Design
sergeychernyshev
25
670
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Navigating Team Friction
lara
183
15k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
How to Ace a Technical Interview
jacobian
276
23k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Bash Introduction
62gerente
608
210k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Transcript
DBݺͼग़͠ճΛݮΒͯ͠ ίΞػೳΛߴԽͨ͠ 2024/04/09 Kyoto Tech Talk Task
Task / த ক GitHub: T45K X (چTwitter): @getupmax ϒϩά:
https://moneyforward-dev.jp/entry/2024/03/28/185934
͜ͷൃදͰ͢͜ͱ • ࢲͨͪͷϓϩμΫτͰߦͬͨߴԽ • ݁Ռͱͯ͠ى͖ͯ͠·ֹͬͨۚෆ߹ • ͔ͦ͜ΒֶΜͩڭ܇ ◦ ૉૣ͘Γ͢ํ๏ ◦
ߦͬͨϙετϞʔςϜͷհ
None
ϓϩμΫτͱ ࿈݁ձܭ
ϚωʔϑΥϫʔυ Ϋϥυ࿈݁ձܭ https://biz.moneyforward.com/consolidated-accounting/
୯ମձܭ ձࣾA ༁ ߴࢼࢉද ୯ମࡒॾද
࿈݁ձܭ ձࣾA ձࣾB ձࣾC
࿈݁άϧʔϓ ࿈݁ձܭ ձࣾA ձࣾB ձࣾC
࿈݁άϧʔϓ ࿈݁ձܭ ձࣾA ձࣾB ձࣾC άϧʔϓձࣾͷߴࢼࢉද + ࿈݁༁ ࿈݁ࡒॾද
ίΞػೳ
Ϋϥυ࿈݁ձܭͷίΞػೳ Ϣʔβ͕࿈݁ࡒॾදͷֹۚΛ ߋ৽͠͏Δૢ࡞Λͨ࣌͠ʹ ͦͷ··࿈݁ࡒॾදΛߋ৽͢Δ
ྫ) ߴࢼࢉදͷऔࠐ ձࣾAͷ ୲ऀ Ϋϥυ࿈݁ձܭ ձࣾAͷ ߴࢼࢉද
ྫ) ߴࢼࢉදͷऔࠐ ձࣾAͷ ୲ऀ 1. ߴࢼࢉදͷऔࠐ 2. ݸผࡒॾදͷ࡞ 3. ଞࣾͷࡒॾදͱ߹Θͤͯ
࿈݁ࡒॾදͷ࡞ Ϋϥυ࿈݁ձܭ ձࣾAͷ ߴࢼࢉද
ྫ) ߴࢼࢉදͷऔࠐ ձࣾAͷ ୲ऀ 1. ߴࢼࢉදͷऔࠐ 2. ݸผࡒॾදͷ࡞ 3. ଞࣾͷࡒॾදͱ߹Θͤͯ
࿈݁ࡒॾදͷ࡞ Ϋϥυ࿈݁ձܭ ձࣾAͷ ߴࢼࢉද
ݸผࡒॾදͷ࡞ ݸผमਖ਼ͷద༻ ௨՟ͷࢉ ظ७རӹͷܭࢉ ҝସࠩଛͷܭࢉ ະܭࢉݸผࡒॾද ܭࢉࡁݸผࡒॾද …
class ݸผमਖ਼ద༻αʔϏε( ࡒॾදϦϙδτϦ, ௨՟ࢉαʔϏε, ) { fun ద༻͢Δ(id) { val
ࡒॾද = ࡒॾදϦϙδτϦ.selectById(id) // ݸผमਖ਼ͷద༻Λߦ͏ val ݸผमਖ਼ద༻ࡁࡒॾද = ... ࡒॾදϦϙδτϦ.update(ݸผमਖ਼ద༻ࡁࡒॾද) // ࣍ͷॲཧͷݺͼग़͠ ௨՟ࢉαʔϏε.ࢉ͢Δ(id)
ݸผࡒॾදͷ࡞ ݸผमਖ਼ͷద༻ ௨՟ͷࢉ ظ७རӹͷܭࢉ ҝସࠩଛͷܭࢉ … select select select select
update update update update
ݸผࡒॾදͷҰׅߋ৽ ݸผमਖ਼ͷద༻ ௨՟ͷࢉ ظ७རӹͷܭࢉ ҝସࠩଛͷܭࢉ … ݸผमਖ਼ͷద༻ ௨՟ͷࢉ ظ७རӹͷܭࢉ ҝସࠩଛͷܭࢉ
… ձࣾA ձࣾB …
ߴԽ
ߴԽલ ݸผमਖ਼ͷద༻ ௨՟ͷࢉ ظ७རӹͷܭࢉ ҝସࠩଛͷܭࢉ … select select select select
update update update update
ߴԽલ ݸผमਖ਼ͷద༻ ௨՟ͷࢉ ظ७རӹͷܭࢉ ҝସࠩଛͷܭࢉ … select select select select
update update update update ͱ͍ͯ
DBݺͼग़͠ճΛݮΒͤΕ ߴԽͰ͖ͦ͏
ϝϞϦʹࡌͤΔ
ߴԽޙ લॲཧ ݸผमਖ਼ͷద༻ ௨՟ͷࢉ ޙॲཧ … select get get set
set update
ߴԽޙ લॲཧ ݸผमਖ਼ͷద༻ ௨՟ͷࢉ ޙॲཧ … select get get set
set update
ߴԽޙ લॲཧ ݸผमਖ਼ͷద༻ ௨՟ͷࢉ ޙॲཧ … select get get set
set update
ߴԽޙ લॲཧ ݸผमਖ਼ͷద༻ ௨՟ͷࢉ ޙॲཧ … select get get set
set update
تͼͷ
ܭࢉϩδοΫΛ৮ΒͣʹߴԽͰ͖ͨ
ֹۚෆ߹োͱݪҼ
ߴԽϦϦʔε͔Β1िؒ΄Ͳͨͬͨ͋Δ
͓٬༷͔Β͍߹Θͤ
ʮԿֹ͔͓͔͍ۚ͠ΜͰ͚͢Ͳʯ
ٸ͍ͰΓ͠
ܭࢉϩδοΫ৮ͬͯͳ͍ͷʹͲ͏ͯ͠
ʢݩ͔Βʣݸผࡒॾදʹ ಉҰՊͷֹ͕ۚ2ؚͭ·Ε͍ͯͨ
ݸผࡒॾදʮצఆՊʯͱʮֹۚʯͷλϓϧ ͷϦετ ݪҼʢܭࢉॲཧʣ צఆՊA ظ७རӹ צఆՊB 100 300 200
ʮظ७རӹʯͷܭࢉॲཧ ݪҼʢܭࢉॲཧʣ צఆՊA צఆՊB 100 200 300 ظ७རӹ צఆՊA צఆՊB
100 200
ܭࢉલ͔Βظ७རӹΛؚΉ͜ͱ͕͋Δ... ݪҼʢܭࢉॲཧʣ צఆՊA ظ७རӹ 100 300 200 צఆՊB
ܭࢉޙɺظ७རӹͷλϓϧ͕৽نՃ ݪҼʢܭࢉॲཧʣ צఆՊA ظ७རӹ 100 300 200 צఆՊB ظ७རӹ 300
צఆՊA ظ७རӹ 100 300 200 צఆՊB
on duplicate key updateͰinsert ݪҼʢߋ৽ॲཧʣ צఆՊA ظ७རӹ 100 300 200
צఆՊB ظ७རӹ 300 צఆՊA 100 200 צఆՊB ظ७རӹ 300 צఆՊA ظ७རӹ 100 300 200 צఆՊB ظ७རӹ 300 insert select
ҙਤ͠ͳ͍ܭࢉॲཧͱ ҙਤ͠ͳ͍ߋ৽ॲཧͰ ݁Ռతʹ߹͍ͯͨ͠
ڭ܇
Γ͠ ࠓճϑΟʔνϟʔϑϥάΛ͏͜ͱͰ σϓϩΠͳ͠Ͱૉૣ͘Γͤͨ ϑΟʔνϟʔϑϥά࠷ߴ
ʮݸผࡒॾදͰצఆՊϢχʔΫʯͱ͍͏ ϧʔϧΛίʔυ্ͰపఈͰ͖ͯͳ͔ͬͨ υϝΠϯϧʔϧΛίʔυʹམͱ͠ࠐΉ όάΛࠞೖͤ͞ͳ͍
• ࿈݁ձܭۀΛ͍ͯ͠Δͱઈରʹؾͮ͘ • Ϣʔβʔͷૢ࡞Λςετʹམͱ͠ࠐΊͯͳ͔ͬͨ ϢʔβʔઢͰͷγφϦΦςετΛॻ͘ όάΛྲྀग़ͤ͞ͳ͍
None