$30 off During Our Annual Pro Sale. View Details »

API を Firebase Realtime Database に移行して気付いたこと

syamaoka
August 28, 2017

API を Firebase Realtime Database に移行して気付いたこと

syamaoka

August 28, 2017
Tweet

More Decks by syamaoka

Other Decks in Technology

Transcript

  1. API Λ Firebase Realtime Database ʹҠߦͯ͠ؾ෇͍ͨ͜ͱ 2017/08/28 syamaoka GCPUG Firebase

    Realtime Database /meetup/1
  2. ࣗݾ঺հ ໊લɿ ࢁԬ ਅ໵ (syamaoka) झຯɿ ɾ MMO RPG ɾ

    PC : Tales Weaver ɾ Mobile : Lineage 2 Revolution ɾ MoBA : VainGlory ୲౰ɿ ɾ iOS, όοΫΤϯυ (API, Batch)
  3. ୲౰தαʔϏεͰꙍ ֵአͭͼ͚Ρ䱛ᚆ • Realtime Database • Remote Config • Firebase

    Authentication • Analytics • App Indexing • Firebase Performance Monitoring
  4. ୲౰தαʔϏεͰꙍ ֵአͭͼ͚Ρ䱛ᚆ • Realtime Database <- ࠓ೔͸͜͜Λத৺ʹ࿩͠·͢ ! • Remote

    Config • Firebase Authentication • Analytics • App Indexing • Firebase Performance Monitoring
  5. ΞδΣϯμ • API -> Firebase Realtime Database • ΞϓϦଆͷ࣮૷ •

    ηΩϡϦςΟϧʔϧʹ͍ͭͯ
  6. Firebase ʹٻΊ͍ͯΔ͜ͱ • API ࡞੒޻਺ͷܰݮ • ύϑΥʔϚϯενϡʔχϯά͔Βͷ୤٫ • ΦϑϥΠϯ࣌ͷσʔλͷѻ͍΍͢͞ʢॲཧͷ؆୯͞ʣ

  7. API -> Firebase Realtime Database

  8. Ұ൪ࠔͬͨʢࠓ΋ෆ҆ʣͷ͸ɺ ੔߹ੑ !

  9. ݁࿦

  10. ΞϓϦέʔγϣϯίʔυΛ৴͡ΔʢఘΊʣ Firebase ͸ RDB Ͱ͸ͳ͍ͨΊɺ֎෦Ωʔ੍໿͕ͳ͍ɻ ͦͷͨΊɺ݁߹͕ඞཁͳՕॴ͸ొ࿥͢ΔࡍʹίʔυͰ֬ೝɻ εΩʔϚϨε(Ұ؏ੑ͕ͳ͍)Ͱ΋ɺ݁߹͢΂͖͔൱͔Λ൑அ͠ɺ ࠷దͳઃܭΛ͍ͯ͘͠ͷ͕ॏཁɻ ! ΤϯδχΞͷ࿹ͷݟͤॴ

    !
  11. ιʔτͷಛ௃ • ΩʔΛࢦఆͯ͠ঢॱͰऔಘ • ฦ٫͢Δσʔλͷॱ൪͸อূ͍ͯ͠ͳ͍

  12. ιʔτͷಛ௃ • ΩʔΛࢦఆͯ͠ঢॱͰऔಘ • ฦ٫͢Δσʔλͷॱ൪͸อূ͍ͯ͠ͳ͍

  13. ฦ٫͢Δσʔλͷॱ൪͸อূ͍ͯ͠ͳ͍ ྫ͑͹ created_at Ͱιʔτ͠ɺ ࠷৽σʔλΛ 10 ݅औಘͨ࣌͠ɺ ฦ٫͞ΕΔσʔλ͸࠷৽σʔλͷ 10 ͕݅ͩɺ

    ฦ٫͞ΕΔ JSON ͷฒͼॱ͸อূ͞Ε͍ͯͳ͍
  14. None
  15. Q. ͭ·ΓΞϓϦଆ͸Ͳ͏͢Ε͹͍͍ʁ A. ฦ٫͞Εͨ஋Λιʔτ͠௚͢ɻ

  16. ߱ॱʹ͢Δʹ͸ʁ • created_at Λ - ͷ஋ʹͯ͠ɺ߱ॱʹͳΔ key Λੜ੒ https://stackoverflow.com/questions/34156996/firebase- data-desc-sorting-in-android/42572025#42572025

    • શ݅औಘͯ͠ΞϓϦଆͰ߱ॱʹฒͼସ͑Δ • QueryLastTo Λ࢖ͬͯ࠷ޙͷσʔλ͔Βऔಘ͢Δ
  17. ϩδοΫॱʹ͢Δʹ͸ʁ ϩδοΫʹΑΔฒͼॱ͸ɺ Firebase Realtime Database ͚ͩͰ͸೉͍͠ɻ

  18. ιʔτ༻ͷσʔλΛ࡞੒ { "articleOrders": { "articleId1": 1, "articleId2": 2 } }

  19. ϝϦοτ • ࠷খݶͷࢀর • ΞϓϦͷมߋͳ͠ʹཪଆͰॱ൪Λมߋग़དྷΔ ※ articles ͷதʹ order Λ༻ҙͨ͠৔߹ɺarticles

    શͯΛಡ ΈࠐΉඞཁ͕͋ΓɺύϑΥʔϚϯε͕ѱ͍ ❌
  20. σϝϦοτ • ߋ৽ִ͕ؒ୹͘ग़དྷͳ͍ • ̍࣌ؒຖʹߋ৽ͱ͔Ͱ͋Ε͹େৎ෉͕ͩɺ5෼ຖͱ͔ͩͱ ͖ͬͱݫ͍͠ • ܭࢉର৅ͷσʔλྔʹݶք͕͋Δ

  21. Cloud Function ͱ࢖͍ ෼͚Α͏ !

  22. Rule ʹ͍ͭͯ

  23. Rule ͸େମҎԼͷ̐ͭ • Read and Write • Type • Require

    • index
  24. ܕͷࢦఆํ๏ { "article": { "title": { ".validate": "newData.isString()" }, "visible":

    { ".validate": "newData.isBoolean()" } } }
  25. ඞਢύϥϝʔλͷࢦఆํ๏ { "article": { ".validate": "newData.hasChildren(['title','visible'])" } }

  26. Index ͷࢦఆํ๏ { "article": { ".indexOn": [ "title" ] }

    }
  27. γϛϡϨʔλ͕͍͢͝ศར !

  28. Demo

  29. ͔͠͠ɺ͜ΕΛखೖྗͰ શ෦؅ཧ͢Δͷ͸େม !

  30. None
  31. ⚠ 8/28 ࣌఺ β ver

  32. Demo

  33. ઃఆϑΝΠϧ https://gist.github.com/bpyamasinn/ c1f62153f0bea8a499c111f4f30c8546

  34. Index ͷઃఆ͚ͩগ͠΍͔͍ͬ Index ͸ Path Ͱࢦఆ͠ͳͪ͘Ό͍͚ͳ͍ͨΊɺ Type ʹهࡌग़དྷͳ͍ͨΊɺδΣωϦΫεΛ࢖ͬͯఆٛͨ͠ࡍʹ ៉ྷʹॻ͚ͳ͍෦෼͕ग़ͯ͘Δ !

  35. Client Side Join

  36. σʔλྫ { "articles" : { "hogeId" : { "title" :

    "λΠτϧ", "category" : "categoryID_1" } }, "categories" : { "categoryID_1" : { "name": "ήʔϜ" } } }
  37. ํ๏ RxSwift ͷ zip Λ༻͍ͯϚʔδ͢Δ

  38. ݁߹ͷྲྀΕ 1. articles ͱ categories Λฒྻʹऔಘ 2. RxSwift ͷΦϖϨʔλ zip

    Λ༻͍ͯɺ྆ํͷσʔλΛऔಘ͢Δ 3. ྆σʔλΛ݁߹͢Δ
  39. ΞϓϦଆͰͷιʔτ΍ߜΓࠐΈ ެࣜυΩϡϝϯτʹهࡌ͞Ε͍ͯΔ௨Γɺ ΫϥΠΞϯταΠυͰͷιʔτ΍ϑΟϧλϦϯά͸ਪ঑͞Εͯ ͍ͳ͍ ❌

  40. ΞϓϦଆͰॲཧग़དྷͳ͍΋ͷ͸ɺ όονͰσʔλΛ༻ҙ͢Δ !

  41. ࣍͸·ͨϦϦʔεޙʹൃද͠·͢ !