Create several nonpersistant objects throug a java script action generate several xas calls

1
Hi there My goal is to create a couple of objects from a json with a java action.  I use mendix 8.15.0 (is not yet on the studio version selector) I have a nonpersistant object smartpostion and the java script to create the objects. Why i have a xas call for eatch object creation? in fast environments this not a problem, but if you have some network latency the this will slow down the process! Is there any other way to instantiate the objects in memory without calling the runtime for any creation? Thanks  Stephan             
asked
2 answers
1

No way around the xas calls but you can speed them up using Promise.all which will run the calls in parallel instead of sequentially. See sample code below
In the end it might be faster to use a microflow for this instead of a java action.

function createObjectAsPromise(entityName) {
  return new Promise((resolve, reject) => {
    mx.data.create({
       entity: entityName,
       callback: resolve,
       error: reject
  });
}

var arr = [0,1,2,3,4,5,6,7,8,9];

// create 10 objects in parallel and store them in an array
let objs = await Promise.all(arr.map(i => createObjectAsPromise("Module.Entity")));

-Andrej

answered
1

Mendix has said that nanoflows are primarily meant for offline apps and are not meant to be used in online apps. I do not expect any optimizations in regard to online apps soon
https://forum.mendix.com/link/questions/89974

-Andrej

 

answered