Data structures 如何为多个视图构造firebase数据

Data structures 如何为多个视图构造firebase数据,data-structures,firebase,Data Structures,Firebase,我是Firebase的新手,我正在Firebase上构建我的第一个应用程序,所以我想问问我目前对应用程序数据结构的计划是否合理 我已经阅读了Firebase的博客文章和一些答案,这有助于我理解“优化数据读取方式”的概念。然而,我的数据将以几种不同的方式读取,这让我感觉可能过于复杂了 背景 该应用程序就像是多个城镇(计划)企业的目录,用于宣传即将到来的活动和优惠。我认为数据层次结构如下: 方案:一个城镇(应用有多个方案) 类别:围绕一个主题的一组企业(例如鞋店) 业务:行政组织(处理账单等)。每

我是Firebase的新手,我正在Firebase上构建我的第一个应用程序,所以我想问问我目前对应用程序数据结构的计划是否合理

我已经阅读了Firebase的博客文章和一些答案,这有助于我理解“优化数据读取方式”的概念。然而,我的数据将以几种不同的方式读取,这让我感觉可能过于复杂了

背景 该应用程序就像是多个城镇(计划)企业的目录,用于宣传即将到来的活动和优惠。我认为数据层次结构如下:

  • 方案:一个城镇(应用有多个方案)
  • 类别:围绕一个主题的一组企业(例如鞋店)
  • 业务:行政组织(处理账单等)。每个企业可以有多个地点(不同城镇的商店)
  • 地点:镇上的一家商店
  • 事件:每个位置都可以促进事件。一个事件可以在多个地点推广,但不一定是在所有业务地点推广
  • 提供:类似于事件,但不同类型的对象
查看数据 应用程序用户可以通过5种方式查看优惠和活动数据:

  • 特定于企业(如Joe's shoes的报价)
  • 对于计划(例如,小镇上的所有优惠)
  • 适用于整个应用程序(例如,任何地方的所有优惠)
  • 在方案的某一类别中(例如,小镇上的所有鞋产品)
  • 在整个应用程序中的一个类别中(例如,任何位置的所有鞋产品)
此外,我需要确保每个企业的管理员可以通过我正在构建的CMS查看/编辑他们企业的所有数据

我的方法 这是我正在考虑使用的数据结构:

   root {
    schemes{
        scheme1{
            name: "smalltown",
            logo: "base64 data",
            bgcolor: "#FF0000"
        },
        scheme2{...}
    },
    businesses{
        business1{
            name: "Joe's Shoes",
            logo: "base64 data",
            locations: {
                location1: true,
                location3: true,
                location15: true
            },
            address_hq: {
                street: "45 Acacia Avenue",
                town: "Bigtown",
                postcode: "BT1 1JS"
            },
            contact_hq: {
                name: "Joe Simpson",
                position: "Owner",
                email: "joe@joesshoes.com",
                tel: "07123 456789"
            },
            subscription: {
                plan: "Standard",
                date_start: "10/10/2015",
                date_renewal: "10/10/2016"
            },
            owner: "james1"
        },
        business2{...}
    },
    locations{
        location1{
            name: "Joe's Shoes",
            logo: "base64 data",
            scheme: "scheme1",
            events: {
                event1: true,
                event27: true
            },
            offers: {
                offer1: true,
                offer6: true
            },
            business: "business1",
            owner: "james1"
        },
        location2{...}
    },
    events{
        event1{
            schemes: {
                scheme1: true,
                scheme4: true
            },
            locations{
                location1: true,
                location21: true
            },
            categories: {
                shoes: true,
                footwear: true,
                fashion: true
            },
            business: "business1",
            date: "5/5/2016",
            title: "The History of Shoes",
            description: "A fascinating talk about the way shoes have...",
            image: "base64 data",
            venue: {
                street: "Great Hotel",
                town: "Bigtown",
                postcode: "BT1 1JS"
            },
            price: "£10"
        },
        event2{...}
    },
    offers{
        offer1{
            schemes: {
                scheme1: true,
                scheme4: true
            },
            locations{
                location1: true,
                location21: true
            },
            categories: {
                shoes: true,
                footwear: true,
                fashion: true
            },
            business: "business1",
            date_start: "5/5/2016",
            date_end: "5/5/2016",
            title: "All children's shoes Half Price",
            description: "Get 50% off all children's shoes - just in time for the summer",
            image: "base64 data",
        },
        offer2{...}
    }
}
以下是类似数据结构的图形,以便于阅读:

我的问题是我是否需要进一步去规范化数据(在更多地方重复更多数据),还是有更好的方法来考虑这一点? 感觉上,由于必须保持数据同步,而不能简单地从一个地方读取数据(例如,我需要使用查询和索引(?)来组合整个计划范围内的事件列表的位置和事件数据),我会遇到潜在的复杂情况

任何关于使此数据结构更高效的建议都将非常有用