Enhancing the efficiency of the Firestore file system

I have developed a user file system that utilizes Firestore for maintaining file metadata and Cloud Storage for Firebase to store the actual files. Instead of solely relying on Firebase Storage, we opted for this combination to incorporate additional attributes to folders, which could pose challenges since GCS does not support "directories."

Within this system, there are two distinct types of items: directories and files. To streamline Firestore writes, child items do not currently have direct references to their parent directories. Parent directories contain an array with the IDs of each child item, and paths are generated by navigating through the children arrays of each parent. This approach simplifies the process of moving files - essentially, shifting a child ID from one directory's array to another. Otherwise, updating the parent reference for every child during folder movement would be necessary.

The data structure is defined as follows:

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: boolean;

}

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, I've noticed that major companies offering drive services tend to include a parent reference for each child item. These companies are less concerned about the overhead of multiple writes, and I have yet to identify any significant shortcomings in this method (aside from minor inconveniences during path construction). So, I'm interested in hearing insights from individuals who may provide reasons for or against adding a parent reference. Thank you!

Answer №1

Currently, in order to optimize Firestore writes, children are not directly linked to their parent directories.

If your concern is the number of writes being performed in Firestore, have you considered utilizing Firebase Realtime Database? Write operations on this platform come at no cost.

Parent directories maintain an array that includes the IDs of each child, allowing paths to be constructed by navigating through these child arrays.

Given that the Realtime Database functions as a complete JSON object, it enables easy creation of references to files in Storage by using key-value pairs.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determine the tuple data type by analyzing a union of tuples using a single element as reference

Looking for a way to work with a union of tuples: type TupleUnion = ["a", string] | ["b", number] | [Foo, Bar] // ... In need of defining a function that can handle any type K extends TupleUnion[0], with the return type being inferred ...

Establishing a variety of platforms within a single firebase project

Embarking on my Firebase journey, I find myself contemplating the ideal project setup. With both Android and iOS apps in mind, I ponder whether it's best to: Opt for a unified project accommodating both Android and iOS, or Establish separate project ...

The element's type is implicitly set to 'any' as the expression of type 'string' is unable to index the 'PointDto' type

Comparing the values of x1, y1 and z1 in PointDto objects (point1 and point2) Example :- point1 => PointDto: { x1: "1.000000", y1: "1.0", z1: undefined pointIndex: 0, } point2 =& ...

Issue "TS2339: Could not find attribute 'X' on type 'Y'" encountered while accessing a data property within a function

New to Vuejs 3 and Typescript here. I have a button that should fetch tasks for a "to do" list when clicked. Below is the script I'm using: <script lang="ts"> import axios from 'axios'; export default { name: 'Todos&a ...

What is the process for including a selected-by option in a VIS network graph?

I'm trying to outline the neighboring nodes of the node that has been selected (highlightNearest). https://i.sstatic.net/lynhu.png Unfortunately, I haven't had success achieving this using JavaScript. Link to StackBlitz ...

Unable to successfully generate work item through VSO SDK

A team is attempting to develop a custom widget on VSTS to facilitate group code reviews. One of the tasks is to create a new work item with the type "Code Review Response" and link it to code changes. However, the current code is not functioning as expect ...

Using Typescript to extract the type from within the function type parameters

I am currently utilizing an imported type definition that contains a function type definition with a fairly complex parameter type: export interface SomeTypeDefinition { someFunction: ( param1: string, param2: { key1: number, key2: s ...

What's the issue with conducting a unit test on a component that has dependencies with further dependencies?

I am experiencing an annoying error that seems to be my mistake and I cannot figure out how to resolve it. The issue lies within a simple component which serves as a top-bar element in my web application. This component has only one dependency, the UserSe ...

Using ESLint to enforce snake_case naming conventions within TypeScript Type properties

When working with TypeScript, I prefer to use snake_case for properties within my Interfaces or Types. To enforce this rule, I have configured the ESLint rule camelcase as follows: 'camelcase': ["error", {properties: "never"}], Even though the E ...

In Vue3, using the script setup feature allows for setting default property values within nested objects

I am developing a component that is designed to accept an object as a prop. In case the object is not provided, I aim to set a default value for it. <script setup lang="ts"> interface LocaleText { text: string; single?: boolean; coun ...

What is the recommended data type to assign to the `CardElement` when using the `@stripe/react-stripe-js` package in TypeScript?

I'm struggling to determine the correct type to use for this import: import { CardElement } from '@stripe/react-stripe-js'; I have successfully used the types Stripe, StripeElements, and CreateTokenCardData for the stripe and elements props ...

The CloudWatch logs for a JavaScript Lambda function reveal that its handler is failing to load functions that are defined in external

Hello there, AWS Lambda (JavaScript/TypeScript) is here. I have developed a Lambda handler that performs certain functions when invoked. Let me walk you through the details: import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda' ...

Troubleshooting a deletion request in Angular Http that is returning undefined within the MEAN stack

I need to remove the refresh token from the server when the user logs out. auth.service.ts deleteToken(refreshToken:any){ return this.http.delete(`${environment.baseUrl}/logout`, refreshToken).toPromise() } header.component.ts refreshToken = localS ...

Using Mongoose $addToSet to add items to an array only if they are unique

Currently, my code is set up to add new flagDtos using $addToSet without consideration for the uniqueness of item.name. However, I want to change this behavior so that: If item.name is unique, add the new flagDtos object. Otherwise, update the existing fl ...

Methods for bypassing a constructor in programming

I am working on a code where I need to define a class called programmer that inherits from the employee class. The employee class constructor should have 4 parameters, and the programmer class constructor needs to have 5 parameters - 4 from the employee c ...

Using babel-loader in an npm package causes issues with the `this` variable

After making the switch from awesome-typescript-loader to babel-loader, I encountered an issue with an npm package we rely on - lodash-inflection. Uncaught TypeError: this.pluralize is not a function at pluralize (lodash-inflection.js:68) Here is a compa ...

Error: The function `this.xhr_.upload.addEventListener` is not supported in Firebase Storage

Having some trouble with file uploads. Small files work fine, but when it comes to larger ones I keep getting this error: this.xhr_.upload.addEventListener is not a function. I'm currently using vue.js along with the firebase 6.1.0 npm package. Th ...

Storing TypeScript functions as object properties within Angular 6

I am working on creating a simplified abstraction using Google charts. I have implemented a chartservice that will act as the abstraction layer, providing options and data-source while handling the rest (data retrieved from a REST API). Below is the exist ...

Invalid access token received from Google API - please check your authorization credentials

Currently, I am attempting to retrieve an access token by making a call to using the following parameters: grant_type: 'refresh_token', client_id: GOOGLE_OAUTH_CLIENT_ID, client_secret: GOOGLE_OAUTH_CLIENT_SECRET, refresh_token: refreshToken I ...

Issue: Unable to locate the name 'ContactField' in Ionic 2

While attempting to use Ionic2 to save a contact, an error occurs when running the app through the command line. The cordova-plugin-contacts has been properly installed. Below is the code snippet: import { Component } from '@angular/core'; impo ...