compendium shennanegins
TIL about
CompendiumContent.getDocuments
taking nedb queries.
More info about nedb queries: https://github.com/louischatriot/nedb#finding-documents13 Replies
The above returns all actors in the compendium with a constitution value greater than 14.
I vaguely remember Atro mentioning this on the mothership at some point, too. IIRC documents fetched by this are not cached though, which can make repeated calls a bit costly.
(Not sure if the caching situation changed in the meantime, so I cannot say whether the warning still applies)
Yeah good call, the docs only mention caching for the singular
getDocument
hmm even with no caching this might be useful for my module 🤔
i mean, its mostly working already, but half of the code is held together with ducttape and best intentions; it would probably be helpful if I use queries to say, get only Spells when I want spells, and only Classes when I want classes, and don't rely on the user doing things the proper way
spoiler alert: they never do
@ccjmk do you use the compendium indexes for your thing?
The query option is why inquired about 5e's data usage a while back, but all the custom stuff you had to do made it a bit difficult for me to recommend this
ehhh to be honest, I .. think ? but I never understood that part deeply. Ghost helped me set up a function I could call with a compendium name, and it would get all the items on the compendium, ready to be added into an actor
and I just parsed it after the fact as I needed
this' Le Function
given that its iterating over
const itemIndex of pack.index.keys()
I think the answer is "technically yes"Looks like yes but also no
Lol
Schrodinger's Indexes
Have a look at the getIndex method on compendium collection
It lets you build and cache a slimmed down version of a compendium's documents locally
So for instance if you need to display all the spells and their levels, you can add spell level to the index
Instead of parsing all spells from the compendium itself
hmm but I will need the full item anyway later, though if getting trimmed versions of documents is performant enough, I guess I could get the minimum I need for displaying/sorting data, and search it on-demand when the user actually submits the actor to be created (which is usually just
name, img, requirement
, and for spells, level + I imagine index to re-find the appropriate documents)right, later you get the full items, but only the ones you actually need