Hello! I’m hoping for some advice on how to best work with recurring dates. In my app, I’ve got the concept of things that occur with a specific frequency (think calendar settings - day of week, intervals, etc.). I’m planning on using https://www.npmjs.com/package/rrule to help me manage this - it takes some options and can generate a list of dates that fall inside the “set” of rules you define, so that you can easily tell if a given date has an occurrence of the event.
Obviously I can’t use that lib in FQL, but I’d really like to handle the logic in UDFs anyway - basically I need to calculate whether or not a set of documents have a recurrence that means they occur on a specific date.
I’m contemplating creating a collection with a unique key that is the value of rrule’s
toString method, and the value is the array of dates from its
all. That way I could pull in the list of dates with an index for the recurrence string and do my date calculations (checking if a date was in the array). I’d essentially be caching the value of a recurrence as a document, and then pulling it up when needed. And, anytime I created a new recurrence rule, I’d need to add it to the cache. They’re idempotent, so I’d never need to edit them once added. The recurrence would never be more than a single year, so never more than 365 entries in the array.
I guess my question is - is this crazy? Would the performance impact of that lookup be too much to be used in a UDF that gets called with some frequency? Anyone else have a different idea of how to approach this? Thanks for any help!