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
250
DB呼び出し回数を減らしてコア機能を高速化した話
Tasuku Nakagawa
April 09, 2024
Tweet
Share
More Decks by Tasuku Nakagawa
See All by Tasuku Nakagawa
withContextってスレッド切り替え以外にも使えるって知ってた?
t45k
3
2.1k
R2DBCを導入しようとした話
t45k
0
360
コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
t45k
0
93
Featured
See All Featured
Bash Introduction
62gerente
610
210k
Into the Great Unknown - MozCon
thekraken
34
1.6k
Producing Creativity
orderedlist
PRO
343
39k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
4
180
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
A Modern Web Designer's Workflow
chriscoyier
693
190k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
VelocityConf: Rendering Performance Case Studies
addyosmani
327
24k
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