I'm executing the below code on a collection which holds the purchased tickets for each event (event id is a reference field within this collection).
I've added a console.time() and it shows that this takes around 0.5 sec. Seems to me a very poor performance as I need to perform additional queries in order to return a valuable result to the end user and the total takes around 1.5 sec.
I've come to know about this since the site monitoring show timeouts when invoking the API.
Is there a way to improve the performance for this kind of query? Will it help to replace the reference field with a regular field which will hold the event id?
const filter = wixData.filter().eq("eventId", eventId);
//const having = wixData.filter().gt("maxPopulation", 1000000);
// .filter(filter)
return wixData.aggregate("MyTickets")
.filter(filter)
.group("ticketId")
.count()
.run()
.then((results) => {
if (results.items.length > 0) {
console.log("items " + JSON.stringify(results.items))
console.timeEnd("getTicketsSum");
// let items = results.items;
// let numItems = results.length;
// let hasNext = results.hasNext();
}
resolve(results);
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
reject(error)
});
The use of indexes should be taken carefully, it has a price in the creation of the item.
By the way, I would like to understand if it is possible to do .group("_createdDate")
Because the information contains, in addition to the day, also an hour and seconds, then the attempt to accumulate, for example, all the donations on the same day is ineffective.
The solution I see is to add a hook that will create another field with the new field type, which is just a date without a time. (big headache all these WIX changes)