#Derive collection from another collection

4 messages · Page 1 of 1 (latest)

arctic olive
#

Hi, I have one collection that I now want to derive another collection from. For this, I need to loop over every element of the first collection and do a nontrivial amount of computation that I don't want to repeat on every collection access.

That's why I created a second collection with a custom loader that calls getCollection on the first collection. This worked fine in astro dev mode, but fails in astro check/astro build, possibly because the load order of the collection is not stable.

Is there an idiomatic way to "preprocess" a collection? Ideally have one collection depend on a second one, similar to Vue's computed properties?

elder cairn
#

Hello. Can you tell us more about this non trivial computation?

arctic olive
#

I'm collecting information into new entities that span across entities from the first collection. One entry in the first collection introduces one or more entries in the second collection, and subsequent entries from the first collection can modify the introduced entries. The second collection should be the resulting set of modified entries.

At first, my mental model was that a collection was loaded once, so deriving another collection would just involve running some code once during startup and the only thing standing in my way is the order of initialization. I now see that it's a bit more complex than this (e.g. hot-reloading of collections), and that deriving a collection from another would not be as easy to implement, especially when it derives from multiple collections. Though the current API should in theory allow for some sort of reactive approach, I think?

elder cairn
#

I'm not sure what bottleneck you're hitting here, the error message could be helpful.
If all you need is a bunch of data from collection1 to be pulled into collection2, I can imagine loading everything as part of your loader, then doing your mapping should do the trick.