首页 > 解决方案 > 这是构建我的firebase数据库的好方法吗?

问题描述

我刚开始使用 Firebase(从 MySQL 开始),在阅读了许多文档/观看教程之后,我尝试为我的“Ebay/Gumtree 风格的应用程序”构建数据库。我所做的有什么重大问题吗?

我试图在我的应用程序的每个屏幕周围构建它,这样我就不会读取不需要的全部数据(我认为这是我应该采用的扁平结构?),但是这个导致了一些数据重复(特别是图像)。

这是构建数据库的好方法吗?我从这里得到了一些提示:

构建我的 Firebase 数据库的最佳方法

{
  "users": {
      "user1": {
          "email": "example@gmail.com",
          "password": "********",
          "first name": "Example",
          "last name": "User",
          "age": "45",
          "gender": "Male",
          "address": "XX1 9YY"
        }
      },
  "upload image": {
      "user1": { 
          "image1": { #path to image
              "condition": "Like New",
              "price": "£100",
              "upload date": "10/10/2019",
              "promoted": True,
              "promoted expiry": "11/11/2019"
            },
          "image2": {
              "condition": "New",
              "price": "£250",
              "upload date": "12/12/2019",
              "promoted": False
            },
      "user2": {
          "image1": {
              "condition": "Used",
              "price": "£50",
              "upload date": "05/05/2019",
              "promoted": True,
              "promoted expiry": "06/06/2019"
            }
          },
  "promoted images": { #max 50 images stored here
      "user1": { 
          "image1": #This image is a duplicated of the image above
              "condition": "Like New",
              "price": "£100",
              "upload date": "10/10/2019",
              "promoted": True,
              "promoted expiry": "11/11/2019"
            },
      "user2": {
          "image1": { #This image is also a duplicate
              "condition": "Used",
              "price": "£50",
              "upload date": "05/05/2019",
              "promoted": True,
              "promoted expiry": "06/06/2019"
            }
          },
  "categories": {
      "category1": {
          "image1": { #This is the third location image1 is stored
              "condition": "Used",
              "price": "£50",
              "upload date": "05/05/2019",
              "promoted": True,
              "promoted expiry": "06/06/2019"
            },
          "image2": {
              "condition": "New",
              "price": "£250",
              "upload date": "12/12/2019",
              "promoted": False
            }
          },
   "reviews": {
       "user1": {
           "review1": {
               "rating": 4,
               "message": "delivered on time, thanks"
            },
           "review2": {
               "rating": 5,
               "message": "great product, delivered quickly"
            },
           }
       "user2": {
           "review1": {
               "rating": 1,
               "message": "terrible service, took ages to arrive and was faulty!"
            },
          },
       },
    },
}

关于我到目前为止所做的事情的一些问题/想法:

拥有同一图像的多个副本是否是一个好主意,因为它可以节省 1000 多个图像。例如,如果我没有“推广图片”但想查找所有推广图片,我必须搜索“上传图片”部分(其中的图片比“推广图片”中的 50 张多得多

每个“类别”都是一个新屏幕,将加载大量图像,因此我尝试将这一部分分开,而不是拥有一个每次加载任何页面时都会读取的主“类别”。

谢谢

标签: firebasenosql

解决方案


推荐阅读