我是Firebase的新手,我正在构建我的第一个应用程序,所以我想我会问我目前应用程序数据结构的计划是否合理。
我已经阅读了Firebase博客帖子和SO上的几个答案,这些答案帮助我理解了“优化数据读取方式”的概念。但是,我的数据将以几种不同的方式阅读,感觉我可能会使事情变得复杂。
该应用程序就像是多个城镇(计划)中的企业目录,以宣传他们即将举办的活动和优惠活动。我想到了这样的数据层次结构:
应用用户可以查看优惠&事件数据有5种方式:
此外,我需要确保每个企业的管理员都可以通过我正在建设的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{...}
}
}
这是一个类似数据结构的图形,以防更容易阅读:
我的问题是我是否需要进一步对数据进行非规范化(在更多地方重复更多数据)或者是否有更好的方法来考虑这一点? 感觉就像我不得不保持数据同步而不能简单地从一个地方读取(例如,我需要使用查询和索引(?)来组合方案的位置和事件数据活动列表)。
任何有关提高数据结构效率的建议都会很棒。