Ta23ka98 / life_snap

1 stars 1 forks source link

スキーマ定義 #24

Closed Ta23ka98 closed 1 year ago

Ta23ka98 commented 1 year ago

概要

・Dart/Firebaseのスキーマ定義をする。

要件

・どんなスキーマにするか議論 ・スキーマをymlファイルで定義 ・スキーマ図の作成

Ta23ka98 commented 1 year ago

MTGのメモ: 今回のアプリに必要そうなフィールドは...

・テキスト ・経度/緯度の座標(マップのピン/ARカメラのオブジェクト表示用) ・画像のパス ・ユーザID ・投稿するID ・ユーザ名 ・いいね数

Ta23ka98 commented 1 year ago

@hirom0922 MTGで仰っていた、スキーマ定義に関する記事を教えて頂きたいです🙇

hirom0922 commented 1 year ago

この辺りです。 https://qiita.com/PictoMki/items/f04e205f6eb45ed9c5bf https://qiita.com/PictoMki/items/52012bf222de1b0440cc

ke158 commented 1 year ago
  最低限いるUSERのスキーマです。

  USER
  String? id,           //ユーザーのuid
  required String userId,  //@user_id
  required String userName, //ユーザー名                       
  @Default('') String selfIntroduction,      //紹介文
  required String profileImageURL,  //ユーザーの画像
  @CreatedAtField() DateTime? createdAt, 登録日時  //@CreatedAtField() timestampとDateTimeの変換処理

FirebaseのサブコレクションにmyPost(自分の投稿) postId 自分が投稿したID createdAt 作成日時

FirebaseのサブコレクションにmyLike(自分がいいねをした投稿) likeId 自分がいいねをした投稿ID createdAt いいねをした日時

フォロワー機能があれば追加でサブコレクションに追加

ke158 commented 1 year ago

 最低限いるPostスキーマ String? id,     // 投稿uid required String postUserId, // ユーザーのuid required String postImage, // 投稿画像 required String title, // タイトル required String content, // 投稿内容 required ○○      //緯度経度 @Default(0) int likeCount, // like数 @CreatedAtField() DateTime? createdAt, //投稿日時

参考程度に見ておいてください

Ta23ka98 commented 1 year ago

@hirom0922 @ke158 ありがとうございます🙌 一通り確認させて頂きました!

この辺りはMTGで話し合う方がいいかもですね🤔

hirom0922 commented 1 year ago

まさたかさんのをベースに物理構造を少し考えてみました。

likeの管理ってFirebaseの場合は、最適解って何だろうというのが、 あります。 自分のlike消したい場合、Documentの1M制限を考えて、 like数と管理を別にしてみたのですが、実装してみないと分かりません。。。

参考のPGに倣いまして、documentid=idなのですが、こちらもやってみる中で、 別項目として必要なのか見てみたいです。

users: #collection documentId: # userId = auth.uid id: string # document Id userName: string selfIntroduction: string profileImageURL: string createdAt: timestamp

posts: #collection documentId: # auto id: string # document Id postUserId: reference postImageURL: string title: string content: string postGeopoint: geopoint likeCount: number createdAt: timestamp

userLikes: #collection documentId: # auto id: string # document Id userId: reference postId: reference createdAt: timestamp

hirom0922 commented 1 year ago

@ke158 @Ta23ka98 こちらの方が良いかな。 #postGeopoint: geopoint ↓ postPosition: (スペース)geohash: string (スペース)geopoint: geopoint

ご参考: https://zenn.dev/wakanao/articles/65972fe4e0894b

hirom0922 commented 1 year ago

@ke158 @Ta23ka98 FreezedとGeoFlutterFireとFireStore連携の件、 かなり、常夜灯(以前の共同開発?)のプロジェクトのソースを参考にしましたが、 位置情報は2階層で登録して、それに対する検索もできているぽいので なるべく早くサンプルとスキーマ定義をあげようかと思います。

結構、まだ散らかっているので、、 けーさんの方でうまくいってそうでしたら、先に上げていただいても大丈夫です。

image image
Ta23ka98 commented 1 year ago

hiromさんのスキーム定義の最終案ですが、一応載せておいてクローズします🙋

users: #collection
  documentId: # userId = auth.uid
    id: string # documentId
    userName: string
    selfIntroduction: string
    profileImageURL: string
    createdAt: timestamp

posts: #collection
  documentId: # auto
    id: string # documentId
    postUserRef: reference
    postImageURL: string
    title: string
    content: string
    postPosition:
      geohash: string
      geopoint: geopoint
    likeCount: number
    createdAt: timestamp

userLikes: #collection
  documentId: # auto
    id: string # documentId
    userRef: reference
    postRef: reference
    createdAt: timestamp
Ta23ka98 commented 1 year ago

myPostsとmyLikePostのサブコレクションを持つと、自分の位置情報を基にしてクエリするため効率的でないとの話が出ました。 そのため、従来通りのスキーマでいきたいと思います。

Ta23ka98 commented 1 year ago

けー さん曰く、myPostsとmyLikePostsをサブコレクションにもつのは ・自分がいいねした投稿と、自分の投稿idをまとめる ため ・マイページで自分の投稿を検索して表示したり、ユーザーを消す際に投稿やいいねをまとめて消す ため とのことです。

MTGで出た「自分の位置情報を基にしてクエリするため効率的でない」という話は、僕が勘違いした結果出てきた結論でした。

これを踏まえ、 @hirom0922 さん @Tomohiro629 さん的には問題なさそうでしょうか? 問題なさそうであれば、また↑のスキーマを修正しようと思います🙋

hirom0922 commented 1 year ago

メリットデメリット比較された方が良いと思います。

Tomohiro629 commented 1 year ago

https://zenn.dev/nananaoto/articles/c26965c5d518e4b235c7

ユーザーを消す際に投稿やいいねをまとめて消すため →この処理が結構面倒くさいかもしれないですね。 僕が知らないだけで他の方法があれば別ですけど。

Ta23ka98 commented 1 year ago

MTGメモ: けいすけ さんが試行錯誤中... ・userLikesをusersのサブコレクションに移動するかも

・(自分の)投稿一覧画面 ・いいねした投稿一覧 これらは、スキーマが確定してから実装する。 それまではUIの方をアサインしていく

hirom0922 commented 1 year ago

userLikesをusersのサブコレクションに移動するかも →userLikesについては、悩んだところなのですが、user 配下の方が良いかもです。 やりやすい方に変えてくださいね。