@yisrael-wix I have been doing some further testing (just can’t let it go) and I think the problem is with the multi-item reference field API implementation.
Here is the scenario: I have two collections connected via a multi-item reference field – Members, which contains 310 items, and Parcels, which contains 502 items. A Member may have more than one Parcel, but a Parcel can only belong to one Member. So, on average, a Member has 1.6 Parcels.
I am using a multi-item reference field because I need to traverse the relationship from Member to Parcel. (A single-item reference field would not let me do this.) The business function is collect the type of Parcels belonging to each Member, then determine a status for the Member based upon the analysis of the Parcel types found.
Here is the web module code. I pass the function a count of Members to retrieve as part of testing; ultimately, the function will spin through all 310 Members. The output of the function is an array containing the Member identifier and a sub-array containing the Parcels for that Member.
export async function arrayBilling(limitcount){
var memArray = [];
var parcelArray = [];
var testArray = [];
var subArray = [];
let memresult = await wixData.query(“Members”)
.limit(limitcount)
.find()
memArray = memresult.items;
for(let m = 0; m<memArray.length;m++) {
let parcelresult = await wixData.queryReferenced(“Members”, memArray[m]._id, “Parcel”)
parcelArray = parcelresult.items;
subArray = [];
for ( let p =0; p<parcelArray.length;p++) {
subArray.push({ “vcc”: parcelArray[p].parcelVcc, “type”: parcelArray[p].parcelType });
}
testArray.push({
“member”: memArray[m].memberId,
“parcels”: subArray,
})
}
return testArray
}
Running this as web module from the backend, I get the following results:
For 10 Members, the function takes 2.4 seconds
For 100 Members, the function takes 6.4 seconds
For 310 Members, the function does not complete, throwing the 14 second timeout error.
If I run the module, but only create memArray (so not executing the wixData.queryReferenced() portion of the code, then the module takes about 1 second whether the limitcount is 10, 100, or 310. This tells me that the majority of the time is being taken in the wixData.queryReferenced() calls.
I suspect that when the wixData.queryReferenced() call is made, is uses a query (scan) type of call, rather than a get (we know the _id) type of call, to process the related Parcels. If so, that would mean the call is reading 1.6 x 502 = 803 Parcels for each Member and 310 x 803 = 248,930 reads for all Members. If the wixData.queryReferenced() was using a get type call, the total would be 310 X1.6 = 496.
This would explain why the web module timeout error gets thrown. I’d ask that you bring this to the developers and see what they have to say. My concern is that this poor performance with a small number of items makes multi-item reference fields a non-starter for any application of volume.