在我的应用程序中,根据日期需要一些固定数据。
我的意图是
避免每年都要更新这些数据,因为它们总是一样的。
根据与之对应的日期放置每条信息。
根据该问题How to organize related temporal and fixed data in Firestore?的讨论,我决定将固定数据存储在一个集合中,然后创建一个calendar
集合,该集合将在给定日期的情况下知道什么内容对应。
同时,我希望避免消耗最少的东西:根据我的模型,将首先读取calendar
,并根据给定日期查找与该日期对应的内容。然后将根据该参考文献搜索内容。
将有两个读数,一个是日历,另一个是具有固定内容的集合。
calendar
集合以及oficio
和laudes
集合将由应用程序同步并缓存。
Firestore-root
|
--- liturgia (collection)
| |
| --- lh (documents)
| |
| --- oficio (collection)
| |
| --- 03070101 (documents)
| |
| --- himno: "Today himno for today oficio"
| |
| --- read: "Today read for today oficio"
|
| --- 03070102 (documents)
| |
| --- himno: "Today himno for today oficio"
| |
| --- read: "Today read for today oficio"
|
| --- 09010325 (documents)
| |
| --- himno: "Today himno for today oficio"
| |
| --- read: "Today read for today oficio"
|
| --- laudes (collection)
| |
| --- 03000101 (documents)
| |
| --- himno: "Today himno for today laudes"
| |
| --- read: "Today read for today laudes"
|
| --- 03000102 (documents)
| |
| --- himno: "Today himno for today laudes"
| |
| --- read: "Today read for today laudes"
|
| --- 09010325 (documents)
| |
| --- himno: "Today himno for today laudes"
| |
| --- read: "Today read for today laudes"
Firestore-root
|
--- calendar (collection)
| |
| --- 20190325 (documents)
| |
| --- oficio: "09010325"
| |
| --- laudes: "09010325"
| |
| --- tercia: "03000301"
|
|
| --- 20190326 (documents)
| |
| --- oficio: "03070102"
| |
| --- laudes: "03000102"
| |
| --- tercia: "03000102"
今天检索oficio
文档的代码,
| --- 09010325 (documents)
| |
| --- himno: "Today himno for today oficio"
| |
| --- read: "Today read for today oficio"
是
String todayDate="20190325"; //getted automatically
final DocumentReference docRef = db.collection("calendar").document(todayDate);
docRef.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot snapshot,
@Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "Listen failed.", e);
//launchVolley();
return;
}
if (snapshot != null && snapshot.exists()) {
String contentPath=snapshot.getString("oficio");
DocumentReference docRef = db.collection("liturgia").document("lh").collection("oficio")
.document(contentPath);
docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
mBreviario = documentSnapshot.toObject(Breviario.class);
Log.w(TAG, documentSnapshot.toString());
showData();
}
});
} else {
//launchVolley();
}
}
});
关于这种情况,我有两个疑问:
我正在进行两次咨询,一次是根据今天的日期获取参考,另一次是根据获取的参考获取固定内容。由于我计划缓存日历,因此当应用程序从缓存中读取日历时,还是仅当它在Firebase中读取日历时,我才需要付费?
因为固定的集合也会被缓存,并且会包含很多信息:每组至少365个文档(oficio
,laudes
等)。就日历而言,缓存将如何工作。我想确定calendar
缓存的优先级,并根据缓存限制添加其他内容。