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
API を Firebase Realtime Database に移行して気付いたこと ver2
Search
syamaoka
October 20, 2017
Programming
1
500
API を Firebase Realtime Database に移行して気付いたこと ver2
iOSDC 2017 Reject Conference days2
syamaoka
October 20, 2017
Tweet
Share
More Decks by syamaoka
See All by syamaoka
API を Firebase Realtime Database に移行して気付いたこと
bpyamasinn
1
790
Other Decks in Programming
See All in Programming
ニーリーにおけるプロダクトエンジニア
nealle
0
340
設計やレビューに悩んでいるPHPerに贈る、クリーンなオブジェクト設計の指針たち
panda_program
6
1.3k
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
160
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
490
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
220
PHPでWebSocketサーバーを実装しよう2025
kubotak
0
110
Benchmark
sysong
0
260
Webの外へ飛び出せ NativePHPが切り拓くPHPの未来
takuyakatsusa
2
350
ASP.NETアプリケーションのモダナイズ インフラ編
tomokusaba
1
410
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
46
30k
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
1
120
ドメインモデリングにおける抽象の役割、tagless-finalによるDSL構築、そして型安全な最適化
knih
11
2k
Featured
See All Featured
Building Adaptive Systems
keathley
43
2.6k
GraphQLとの向き合い方2022年版
quramy
47
14k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
How to Ace a Technical Interview
jacobian
277
23k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.3k
How to Think Like a Performance Engineer
csswizardry
24
1.7k
Designing for humans not robots
tammielis
253
25k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.5k
How to train your dragon (web standard)
notwaldorf
92
6.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
233
140k
Navigating Team Friction
lara
187
15k
Transcript
API Λ Firebase Realtime Database ʹ Ҡߦͯ͠ؾ͍ͨ͜ͱ 2017/10/20 syamaoka iOSDC
2017 Reject Conference days2
ࣗݾհ ໊લɿ ࢁԬ ਅ ( syamaoka ) झຯɿ ɾ MoBA
: VainGlory ୲ɿ ɾ iOS, όοΫΤϯυ
ҙ ⚠ ͜ͷൃද Firebase Realtime Database 8ׂ, iOS 2ׂͷߏͰ ͢
iOS͕ςʔϚͰ͕͢ɺ ࠓճ Realtime Database (ҎԼRTDB) ʹ͍ͭͯͲΜͲΜޠͬ ͍͖ͯ·͢ʂ
࠷ॳʹɾɾ
ϦδΣΫτ͞Εͯ Α͔ͬͨ !
Կނʁ ʮRTDB ༷ʑͳΞϓϦͰ͑Δʯ Λओு͔ͨͬͨ͠ ! ͔͠͠ɺ৽͍͠ RTDB ͷ࣍ੈσʔλϕʔε ͕ൃද͞Ε·͠ ͨɻ
Cloud Firestore ެ։
୲தͷαʔϏεͰ༻͍ͯ͠Δػೳ • Realtime Database • Remote Config • Firebase Authentication
• Analytics • App Indexing • Firebase Performance Monitoring
୲தαʔϏεͰꙍ ֵአͭͼ͚Ρ䱛ᚆ • Realtime Database <- ͜͜த৺!ʢFirestore ͍͍ͨ"ʣ • Remote
Config • Firebase Authentication • Analytics • App Indexing • Firebase Performance Monitoring
ΞδΣϯμ • API -> RTDB • Client Side Join •
RTDB ͷ௨৴ྔ֬ೝํ๏ • API, RTDB, Firestore ͷൺֱ
API -> RTDB
RTDB ʹٻΊ͍ͯΔ͜ͱ • API ࡞ͷܰݮ • ύϑΥʔϚϯενϡʔχϯά͔Βͷ٫ • ΦϑϥΠϯ࣌ͷσʔλͷѻ͍͢͞ʢॲཧͷ؆୯͞ʣ
ҠߦͰҰ൪ࠔͬͨͷɺ߹ੑ ! Firebase RDB Ͱͳ͍ͨΊɺ֎෦Ωʔ੍͕͋Γ·ͤΜɻ ͦͷͨΊɺ݁߹͕ඞཁͳՕॴొ͢ΔࡍʹίʔυͰ֬ೝɻ εΩʔϚϨεͰɺ݁߹͖͔͢൱͔Λஅ͠ɺ ࠷దͳઃܭΛ͍ͯ͘͠ͷ͕ॏཁͰ͢ɻ !
ΤϯδχΞͷͷݟͤॴ !
͕ͣͩͬͨɾɾʂ
Firestore Ͱɺ ͋Δఔղফ͞ΕΔ !
Firestore ͷ৽͍͠σʔλܕ "Reference" Λ͏
RTDB ͷ߹ let articleId: String // primary key let categoryId:
String // foreign key let title: String // ͦͷଞͷϑΟʔϧυ { "articles" : { "articleId1" : { "title" : "λΠτϧ", "category" : "categoryId1" } }, "categories" : { "categoryId1" : { "name": "ήʔϜ" } } }
RTDB ͷ߹ let articleId: String // primary key let categoryId:
String // foreign key let title: String // ͦͷଞͷϑΟʔϧυ { "articles" : { "articleId1" : { "title" : "λΠτϧ", "category" : "categoryId1" <- ͜Ε͕ category Ͱ͋Δͱ͍͏อূग़དྷͳ͍ ! } }, "categories" : { "categoryId1" : { "name": "ήʔϜ" } } }
Firestore ͷ߹ let articleId: String // primary key let categoryId:
DocumentReference // foreign key let title: String // ͦͷଞͷϑΟʔϧυ
ιʔτ
RTDB ͷιʔτͷಛ • ΩʔΛࢦఆͯ͠ঢॱͰऔಘ • ฦ٫͢Δσʔλͷॱ൪อূ͍ͯ͠ͳ͍
RTDB ͷιʔτͷಛ • ΩʔΛࢦఆͯ͠ঢॱͰऔಘ • ฦ٫͢Δσʔλͷॱ൪อূ͍ͯ͠ͳ͍
ฦ٫͢Δσʔλͷॱ൪อূ͍ͯ͠ͳ͍ (ྫ) ࠷৽σʔλΛ 3 ݅औಘ͢ΔͨΊɺ࡞࣌Ͱιʔτ͢Δ reference.child("articles").queryLimited(toFirst: 3).orderBy("created")
None
݁Ռ ฦ٫͞ΕΔσʔλ࠷৽σʔλͷ 3 ͕݅ͩɺ ฦ٫͞ΕΔ JSON ͷฒͼॱอূ͞Ε͍ͯͳ͍ Ҿ༻ݩ: https://firebase.google.com/docs/database/rest/retrieve-data?hl=ja#section-rest- ordered-data
Q. ΞϓϦଆͲ͏͢Ε͍͍ʁ A. ฦ٫͞ΕͨΛιʔτ͢͠ɻ
͕ͣͩͬͨɾɾʂ
Firestore Ͱ ղফ͞ΕΔ !
Firestore (ιʔτฤ) • ߱ॱʹରԠ ৄࡉͪ͜Β • ෳ߹ Index ʹରԠ ৄࡉͪ͜Β
• ฦ٫͞ΕΔσʔλͷฒͼॱ͕ἧ͍ͬͯΔ
RTDB Ͱ߱ॱʹ͢Δʹʁ ͪ͜ΒΛࢀর͍ͯͩ͘͠͞ ! https://speakerdeck.com/bpyamasinn/api-wo-firebase- realtime-database-niyi-xing-siteqi-fu-itakoto
ϩδοΫॱʹ͢Δʹʁ ϩδοΫʹΑΔฒͼॱɺ DB Λࢀর͢Δํ๏Ͱ͍͠
Index ࡞ { "articleOrders": { "articleId1": 1, "articleId2": 2 }
}
ϝϦοτ • ࠷খݶͷࢀর • ΞϓϦଆͷมߋͳ͠Ͱॱ൪Λมߋग़དྷΔ ※ articles ͷதʹ order Λ༻ҙͨ͠߹ɺarticles
શͯΛಡ ΈࠐΉඞཁ͕͋ΓɺύϑΥʔϚϯε͕ѱ͍ ❌
σϝϦοτ • ߋ৽ִ͕ؒ͘ग़དྷͳ͍ • ̍࣌ؒຖͷߋ৽Ͱ͋Εେৎ͕ͩɺ5ຖͳͲ͘͢Ε ͢Δ΄Ͳίετ͕େ͖͘ͳΔ • ϩδοΫʹݶք͕͋Δ • ཪͰॲཧͯ͠Δͷ௨৴ྔ͕૿͑Δ
σϝϦοτ • ߋ৽ִ͕ؒ͘ग़དྷͳ͍ • ̍࣌ؒຖͷߋ৽Ͱ͋Εେৎ͕ͩɺ5ຖͳͲ͘͢Ε ͢Δ΄Ͳίετ͕େ͖͘ͳΔ • ϩδοΫʹݶք͕͋Δ • ཪͰॲཧͯ͠Δͷ௨৴ྔ͕૿͑Δ
্هͷσϝϦοτ͕ڐ༰ग़དྷͳ͍αʔϏεͷ߹ɺAPI Ͱ։ ൃͨ͠ํ͕Α͍͔
Client Side Join Client Side Join RTDB ͱ Firestore
྆ํͰ͑Δख๏
σʔλྫ
RTDB { "articles" : { "hogeId" : { "title" :
"λΠτϧ", "category" : "categoryID_1" } }, "categories" : { "categoryID_1" : { "name": "ήʔϜ" } } }
Firestore
RTDB ͷ Client Side Join Λલఏͱ͠ ͨΞʔΩςΫνϟʹ͢Δඞཁ͕͋Δ
None
None
None
None
݁߹ͷྲྀΕ 1. articles ͱ categories ͷ Observable Λ༻ҙ 2. RxSwift
ΦϖϨʔλ zip Λར༻ Observable.zip(articles, categories)ɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹ 1. ྆σʔλΛ݁߹͠ɺมॲཧΛ͔͚Δ Observable.zip(articles, categories) {($0, $1)}.map(Translator())
RTDB ͷ௨৴ྔ֬ೝํ๏
ํ๏ 3ͭ • Xcode Ͱ௨৴ྔΛݟΔ • Charles Ͱ௨৴ྔΛݟΔ • Firebase
CLI ͷ profile Ͱ௨৴ྔΛݟΔ
ํ๏ 3ͭ • Xcode Ͱ௨৴ྔΛݟΔ • Charles Ͱ௨৴ྔΛݟΔ • Firebase
CLI ͷ profile Ͱ௨৴ྔΛݟΔ <- ͜͜ͷ͓Λ͠· ͢
Firebase CLI ͱʁ Firebase ϓϩδΣΫτͷཧɺදࣔɺσϓϩΠΛߦ͏ͨΊͷ ͞·͟·ͳπʔϧΛఏڙͯ͘͠ΕΔ Command Line Interface
͍ํ 1. https://firebase.google.com/docs/cli/?hl=ja ͷಋೖखॱʹै ͏ 2. iPhone γϛϡϨʔλΛ্ཱͪ͛Δ 3. firebase
database:profile --project {ϓϩδΣΫτID} Λ λʔϛφϧͰ࣮ߦ 4. iPhone γϛϡϨʔλͰܭଌ͍ͨ͠खॱͰಈ͔͢
݁Ռը໘
ҙ ⚠ ͜ͷ௨৴ྔ࣮ࡍͷμϯϩʔυྔΑΓগͳ͍ͷͰɺ͋͘·Ͱ ࢀߟͰ͢ Ҿ༻ : https://firebase.google.com/docs/database/usage/profile
API, RTDB, Firestore ൺֱ
API ͕༏Ε͍ͯΔ • ΞϓϦଆͷ࣮͕γϯϓϧ • WebαʔϏεల։͍ͯ͠Δ߹ɺAPI Λ͍·ΘͤΔ • Ωϟογϡώοτ͕ߴ͍αʔϏεྉ͕ۚ҆͘͢Ή •
ϦϦʔεޙʹ͕ൃੜͨ࣌͠ʹɺAPI ଆͰΧόʔ͍͢͠
API ͕༏Ε͍ͯΔ • ΞϓϦଆͷ࣮͕γϯϓϧ • WebαʔϏεల։͍ͯ͠Δ߹ɺAPI Λ͍·ΘͤΔ • Ωϟογϡώοτ͕ߴ͍αʔϏεྉ͕ۚ҆͘͢Ή •
ϦϦʔεޙʹ͕ൃੜͨ࣌͠ʹɺAPI ଆͰΧόʔ͍͢͠ ....(ਖ਼ɺࢁ΄Ͳ͋Δ ! )
RTDB ͕༏Ε͍ͯΔ • API ͷ։ൃ͕ෆཁ • ΦϑϥΠϯରԠָ͕ • ӡ༻͞Ε͍ͯΔͷͰɺࢀߟʹͳΔهࣄ͕ଟ͍
Firestore ͕༏Ε͍ͯΔ • API ͷ։ൃ͕ෆཁ • RTDB ͱൺͯ ΦϑϥΠϯରԠָ͕ •
RTDB ͱൺͯ order, query ͕༏Ε͍ͯΔ • ࠓޙͲΜͲΜ৽͍͠ػೳ͕Ճ͞Ε͍ͯ͘༧ఆ • ՝ۚϞσϧ͕௨৴ྔͰͳ͘ɺࢀরճͳͷͰઅ͍͢͠
Firestore ͕༏Ε͍ͯΔ • API ͷ։ൃ͕ෆཁ • RTDB ͱൺͯ ΦϑϥΠϯରԠָ͕ •
RTDB ͱൺͯ order, query ͕༏Ε͍ͯΔ • ࠓޙͲΜͲΜ৽͍͠ػೳ͕Ճ͞Ε͍ͯ͘༧ఆ • ՝ۚϞσϧ͕௨৴ྔͰͳ͘ɺࢀরճͳͷͰઅ͍͢͠ ....( RTDB ͱൺֱ͍͍ͯ͠ॴଞʹ͋Δ ! )
Firestore ͷαϯϓϧͪ͜Β https://github.com/firebase/quickstart-ios/tree/master/ firestore
Bolt Firestore ʹରԠ͢Δ https://github.com/firebase/bolt/issues/216
·ͱΊ • RTDB ૉΒ͍͠ɻͨͩɺFirestore ͬͱૉΒ͍͠ ! • σʔλͷ݁߹ΛΞϓϦଆͰߦ͏࣌ RxSwift ͷ
zip Λ͏ͱ ؆୯ʹ࣮͕Մೳ • API -> RTDB, Firestore ͷҠߦߟྀ͢Δ͕ͱͯଟ͍ ʢಛʹඅ༻໘ʣͷͰɺ Ҡߦ͢ΔࡍྉۚͱͷݟੵΓΛೖ೦ʹߦ͍·͠ΐ͏ ʢռΊʣ