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
770
Other Decks in Programming
See All in Programming
テストコード書いてみませんか?
onopon
2
360
AWSのLambdaで PHPを動かす選択肢
rinchoku
2
400
AWSマネコンに複数のアカウントで入れるようになりました
yuhta28
2
120
自分ひとりから始められる生産性向上の取り組み #でぃーぷらすオオサカ
irof
7
2k
個人アプリを2年ぶりにアプデしたから褒めて / I just updated my personal app, praise me!
lovee
0
250
ATDDで素早く安定した デリバリを実現しよう!
tonnsama
1
2.2k
ecspresso, ecschedule, lambroll を PipeCDプラグインとして動かしてみた (プロトタイプ) / Running ecspresso, ecschedule, and lambroll as PipeCD Plugins (prototype)
tkikuc
2
2.1k
Amazon Nova Reelの可能性
hideg
0
240
為你自己學 Python
eddie
0
530
Fixstars高速化コンテスト2024準優勝解法
eijirou
0
190
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
3
190
Amazon Bedrock Multi Agentsを試してきた
tm2
1
160
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.8k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Building an army of robots
kneath
302
45k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
The Cost Of JavaScript in 2023
addyosmani
47
7.2k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
590
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 ͷҠߦߟྀ͢Δ͕ͱͯଟ͍ ʢಛʹඅ༻໘ʣͷͰɺ Ҡߦ͢ΔࡍྉۚͱͷݟੵΓΛೖ೦ʹߦ͍·͠ΐ͏ ʢռΊʣ