Hi
Based on the question: https://forums.fauna.com/t/get-count-of-related-documents/3683 I have created a Next React Server component that gets the Lists and a count of the associated Todo’s.
import { Client, fql } from "fauna";
const client = new Client({
secret: process.env.FAUNA_KEY,
});
const getAllLists = fql`List.all().map(list => list {
id,
ts,
name,
todoCount: Todo.byList(list).count()
})`;
export default async function Home() {
const response = await client.query(getAllLists);
const { data } = response.data;
return (
<main>
{data.map(({ id, name, todoCount }) => (
<div key={id}>
{name} {todoCount}
</div>
))}
</main>
);
}
I understand that this solution works great for a ToDo App. But when I theoretically have thousends of Todo’s in a List then it is probably a performance issue and then it would be better to have like a Summy Document for each list, where the count of the ToDo’s are aggregated.
But then I need to update the Summary document when a ToDo gets created or deleted or moved to another list.
Is there a way in fauna that theese operation could be done server side and not in the client logic?
Like a detection of these events?
Thanks for the help. I am still new to fauna.
V10 seams to be very powerful.