英文:
Firestore file system optimization
问题
I'm writing a basic user file system that uses Firestore for file metadata and Cloud Storage for Firebase for storing actual files. Firebase Storage isn't exclusively used because we want to add several attributes to folders that could become cumbersome considering GCS doesn't have "directories".
In this system, there are two types of items: directories and folders. To limit Firestore writes, children currently do not have a reference to their parent directories. Parent directories have an array containing each of their child IDs, and paths are built by traversing down each parent's children array. This is done to make moving files easier (basically, we switch the child ID from one directory's array to another directory's array). Otherwise, we would have to write a new parent into every child whenever a folder moves.
This is the data structure:
interface Directory {
id: string;
entryType: "directory";
name: string;
createdTimestamp?: Timestamp;
modifiedTimestamp?: Timestamp;
owners?: string[];
viewers?: string[];
editors?: string[];
children: string[]; // contains references to File's ID
color: string;
icon: string;
root: bool;
}
interface File {
id: string;
entryType: "file";
name: string;
createdTimestamp?: Timestamp;
modifiedTimestamp?: Timestamp;
owners?: string[];
viewers?: string[];
editors?: string[];
storagePath: string;
storageBucket: string;
contentType: string;
metadata: Record<string, string>;
}
However, based on my observations, large companies providing drive services tend to provide a parent reference with each of their children. These large companies are less constrained by the cost of multiple writes and I have yet to find a fatal flaw in this system (besides some inconvenience when constructing file paths), so I'm curious whether someone smarter than I am can explain why a parent reference should or should not be added? Thanks!
英文:
I'm writing a basic user file system that uses Firestore for file metadata and Cloud Storage for Firebase for storing actual files. Firebase Storage isn't exclusively used because we want to add several attributes to folders that could become cumbersome considering GCS doesn't have "directories".
In this system, there are two types of items: directories and folders. To limit Firestore writes, children currently do not have a reference to their parent directories. Parent directories have an array containing each of their child IDs, and paths are built by traversing down each parent's children array. This is done to make moving files easier (basically, we switch the child ID from one directory's array to another directory's array). Otherwise, we would have to write a new parent into every child whenever a folder moves.
This is the data structure:
interface Directory {
id: string;
entryType: "directory";
name: string;
createdTimestamp?: Timestamp;
modifiedTimestamp?: Timestamp;
owners?: string[];
viewers?: string[];
editors?: string[];
children: string[]; // contains references to File's ID
color: string;
icon: string;
root: bool;
}
interface File{
id: string;
entryType: "file";
name: string;
createdTimestamp?: Timestamp;
modifiedTimestamp?: Timestamp;
owners?: string[];
viewers?: string[];
editors?: string[];
storagePath: string;
storageBucket: string;
contentType: string;
metadata: Record<string, string>
}
However, based on my observations, large companies providing drive services tend to provide a parent reference with each of their children. These large companies are less constrained by the cost of multiple writes and I have yet to find a fatal flaw in this system (besides some inconvenience when constructing file paths), so I'm curious whether someone smarter than I am can explain why a parent reference should or should not be added? Thanks!
答案1
得分: 1
为了限制Firestore的写入操作,子文档目前没有对其父目录的引用。
如果问题与您在Firestore中执行的写入操作数量有关,那么为什么不使用Firebase实时数据库呢?写入操作是免费的。
父目录包含一个包含其每个子文档ID的数组,并且路径是通过遍历每个父文档的子文档数组来构建的。
由于实时数据库是一个完整的JSON对象,您可以简单地创建对存储中文件的引用,使用键值对。
英文:
> To limit Firestore writes, children currently do not have a reference to their parent directories.
If the problem is related to the number of writes you perform in Firestore, then why are you not using Firebase Realtime Database? The write operations are free of charge.
> Parent directories have an array containing each of their child IDs, and paths are built by traversing down each parent's children array.
Since the Realtime Database is an entire JSON object you can simply create references to the files in Storage, using key-value pairs.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论