refactor!: use consistent structure for particles
Making the firestore subcollections the same name helps with creating indices and queries across subcollections of different depths. This also prevents the need for conditional logic for network root / top-level particles.
This commit is contained in:
@@ -35,13 +35,13 @@ export function parseParticlePath(path: ParticlePath): {
|
|||||||
* Convert a ParticlePath to the Firestore document path for that particle.
|
* Convert a ParticlePath to the Firestore document path for that particle.
|
||||||
*
|
*
|
||||||
* Firestore structure:
|
* Firestore structure:
|
||||||
* /net1 → networks/net1/particles (collection)
|
* /net1 → networks/net1/children (collection)
|
||||||
* /net1/p1 → networks/net1/particles/p1 (document)
|
* /net1/p1 → networks/net1/children/p1 (document)
|
||||||
* /net1/p1/p2 → networks/net1/particles/p1/children/p2 (document)
|
* /net1/p1/p2 → networks/net1/children/p1/children/p2 (document)
|
||||||
*/
|
*/
|
||||||
export function toFirestoreDocPath(path: ParticlePath): string {
|
export function toFirestoreDocPath(path: ParticlePath): string {
|
||||||
const { networkId, segments } = parseParticlePath(path);
|
const { networkId, segments } = parseParticlePath(path);
|
||||||
const base = `networks/${networkId}/particles`;
|
const base = `networks/${networkId}/children`;
|
||||||
if (segments.length === 0) return base;
|
if (segments.length === 0) return base;
|
||||||
|
|
||||||
const parts: string[] = [base, segments[0]];
|
const parts: string[] = [base, segments[0]];
|
||||||
@@ -54,9 +54,9 @@ export function toFirestoreDocPath(path: ParticlePath): string {
|
|||||||
/**
|
/**
|
||||||
* Convert a ParticlePath to the Firestore collection path for its children.
|
* Convert a ParticlePath to the Firestore collection path for its children.
|
||||||
*
|
*
|
||||||
* /net1 → networks/net1/particles (root particles)
|
* /net1 → networks/net1/children (root particles)
|
||||||
* /net1/p1 → networks/net1/particles/p1/children
|
* /net1/p1 → networks/net1/children/p1/children
|
||||||
* /net1/p1/p2 → networks/net1/particles/p1/children/p2/children
|
* /net1/p1/p2 → networks/net1/children/p1/children/p2/children
|
||||||
*/
|
*/
|
||||||
export function toFirestoreChildrenPath(path: ParticlePath): string {
|
export function toFirestoreChildrenPath(path: ParticlePath): string {
|
||||||
const { segments } = parseParticlePath(path);
|
const { segments } = parseParticlePath(path);
|
||||||
|
|||||||
Reference in New Issue
Block a user