“the best method for optimizing fauna queries in a serverless setting” is a pretty broad question. If you have specific query patterns you would like help optimizing, then please share some more details about your data and how you need to work with it.
In general, though, optimizing a query is going to primarily involve setting up indexes appropriate for your query patterns. Make sure that your indexes include covered values when possible, so that you can avoid reading each and every individual document. Indexes - Fauna Documentation
There shouldn’t need to be anything special you do to configure your client with AWS lambda. We do have one important recommendation to create your client within the handler to avoid issues with Lambda freeze/thaw operations (this is in the v4 docs but applies to v10 as well): Known issues - Fauna Documentation
I work with User activity logs are included in the dataset, and it can get bigger. Filters by user ID; activity type, and time ranges are common query structures.
I am going to be sure to set up indexes properly based on your advice. Could you give examples for building indexes for these kinds of query patterns?
any advice on effectively managing scrolling in Faunadb would be very valued.
and use it like this to get all activities for a give user, of type “sports”, and having a time recorded in the first week of June. I’ve also included .title as a value so we can read that from the index instead of fetching the documents.
let user = user.byId("1234")!
Activity.by_user_type__time_asc(
user,
"sports",
{ from: Time("2024-06-01T00:00:00Z"), to: Time("2024-06-08T00:00:00Z")}
) {
id,
title,
}
Scrolling
Do you mean fetching additional results as you reach the bottom of a list?
Check out our docs on pagination here. Fauna’s cursor-based pagination is perfectly suited for this task.