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
510
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
理論と実務のギャップを超える
eycjur
0
170
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
360
その面倒な作業、「Dart」にやらせませんか? Flutter開発者のための業務効率化
yordgenome03
1
140
Writing Better Go: Lessons from 10 Code Reviews
konradreiche
3
5.8k
釣り地図SNSにおける有料機能の実装
nokonoko1203
0
190
SwiftDataを使って10万件のデータを読み書きする
akidon0000
0
240
バッチ処理を「状態の記録」から「事実の記録」へ
panda728
PRO
0
190
3年ぶりにコードを書いた元CTOが Claude Codeと30分でMVPを作った話
maikokojima
0
620
NIKKEI Tech Talk#38
cipepser
0
130
開発組織の戦略的な役割と 設計スキル向上の効果
masuda220
PRO
6
970
テーブル定義書の構造化抽出して、生成AIでDWH分析を試してみた / devio2025tokyo
kasacchiful
0
260
エンジニアインターン「Treasure」とHonoの2年、そして未来へ / Our Journey with Hono Two Years at Treasure and Beyond
carta_engineering
0
410
Featured
See All Featured
Docker and Python
trallard
46
3.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
54k
The Straight Up "How To Draw Better" Workshop
denniskardys
238
140k
How to Ace a Technical Interview
jacobian
280
24k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Balancing Empowerment & Direction
lara
5
700
Thoughts on Productivity
jonyablonski
70
4.9k
Faster Mobile Websites
deanohume
310
31k
RailsConf 2023
tenderlove
30
1.3k
YesSQL, Process and Tooling at Scale
rocio
173
15k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
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 ͷҠߦߟྀ͢Δ͕ͱͯଟ͍ ʢಛʹඅ༻໘ʣͷͰɺ Ҡߦ͢ΔࡍྉۚͱͷݟੵΓΛೖ೦ʹߦ͍·͠ΐ͏ ʢռΊʣ