PLease, help me to solve the rebus.
I have a collection ‘Soci’, the records are the members of an association.
Each member have a code: tessera.
After some time you need to refresh ‘Soci’ collection with new members.
So via db_manager I load the new .csv in ‘importSoci’ with 500 or 1000 records, then I run this routine in order to update ‘Soci’.
The code seems good, BUT when I run the code I get in console:
« #GatewayTimeout » or «WebMethod request #timedout after 14 seconds».
‘Soci’ collection rise from eg. 200 members until to 300 members, then it stops.
Why ?
The routine is in the backend.
thanks in advance
Mauro
import wixData from 'wix-data';
export async function importaSoci() {
let options = {suppressAuth:true, suppressHooks:true}
let arraySoci =[];
// create 'arraySoci' from 'importSoci' collection
await importaArray(options).then (res => {arraySoci=res});
// FOR: search for the same ‘tessera’ into ‘Soci' collection
for (let i=0; i<arraySoci.length; i++) {
await cercaTessera(arraySoci[i].tessera, options)
.then ( async res => {
// if don’t find the same ‘tessera’ insert new record
if(res==null){
await insertSoci(arraySoci[i], options);
} else {
arraySoci[i]._id = res._id;
await updateSoci(arraySoci[i], options)
}
})
.then(() => {erase("importSoci")})
.catch(err => {return err})
} // CLOSE FOR LOOP
return "REFRESH OK"
}
//------ FUNCTIONS ________
async function importaArray (op) {
return await wixData.query("importSoci", op)
.limit(1000)
.find()
.then( (results) => {
return results.items } )
.catch( err => {return err})
}
async function cercaTessera(tessera, op) {
return await wixData.query("Soci", op)
.limit(1000)
.eq("tessera", tessera)
.find()
.then( (results) => {
return results.items[0] } )
.catch( err => {return err})
}
async function updateSoci(record,op) {
return await wixData.update("Soci", record, op)
.then( (res) => {return res.items})
.catch(err => {return err})
}
async function insertSoci(record, op) {
return await wixData.insert("Soci", record, op)
.then( (res) => {return res.items})
.catch(err => {return err})
}