Get documents/events after timestamp - inverse of At function

I want to run a site as cheap and effective as possible. Given that Fauna already stores the history of every document, what I’m trying to achieve is generate a static webpage, save the timestamp of the database at the time of generation inside the static webpage. Then I’d want to hydrate the generated HTML in a front-end JavaScript framework and after that only fetch for the events after the saved timestamp to achieve least amount of reads as possible.

  1. Is this possible?

  2. At:
    a. I found At but it does the reverse, should I do a Difference of At and the index of all documents in the collection to get all the documents after the timestamp?

    b. How many reads would that give me – would it be any better than just getting all the elements?

  3. Should I just index the timestamps somehow?

FEATURE REQUESTS

  1. Could an inverse argument be added to At, to get things after and not before the given ts?

  2. Events
    a. Could the Events function accept afterTimestamp argument to only get me some events?
    b. Are Events indexable so I can do this manually?

Thanks.

Hi @jcubed,

Just wondering if you need to get documents created after the saved timestamp.
In that case, you might try to create and index that way

CreateIndex({name:'ref_by_ts',source:Collection(<collection name>),values:[{field:['ts']},{field:['ref']}]})

And then querying it using Range():
Paginate(Range(Match('ref_by_ts'),[<saved timestamp>],[ToMicros(Now())]))

You get back something like this:
{ data: [ [1594744613090000, Ref(Collection("test"), "271041967442362886")], [1594744629510000, Ref(Collection("test"), "271041984667320837")] ] }

At this point, having the Ref , you can get the full documents created after the saved ts.

Not sure I answered your question. In case, let me know and I can try to help you further.

Luigi Servini

2 Likes

This is great, thank you!