Do RESTlets support any of the promise related syn...
# suitescript
l
Do RESTlets support any of the promise related syntax in the search module?
e
You can use the Promise APIs in a Restlet, yes, but the Restlet execution itself is synchronous, so if the Restlet returns before the Promise resolves, your Promise callback won't execute
We recently tried to optimize a Restlet by employing
Promise.all()
to run several queries in parallel, but that ended up making the total runtime even longer. No clue why that was the case though.
l
Thank you, I have a restlet that returns saved search data that I was looking to optimize to process each page of the search in parallel, weird that promise.all would slow down runtime that was going to be my solution
e
Our attempt is anecdotal of course, so it might still be worth a try
c
That seems a bit odd though doesn't it? That it runs synchronously when it has async capability?
b
a script that is allowed 1 database connection cant make multiple queries at the same time
c
what's the point of the async capabilities then? just to kick off like a save or something and keep going?
e
How are we supposed to know how many database connections a script is allowed?
c
its pretty interesting im curious on it now
e
The point I suppose is to avoid the wait for that one DB connection, but piling on additional DB connections will have no effect and will only degrade performance with the increased overhead of wrapping it in a Promise
That's just a hypothesis based on the comment; I do not have access to battk's mystic arcanum
🤣 3
c
interesting. I've only used the promises client side so far so this is good info
b
its not necessarily 1 per script, but there is a finite number of connections a database can serve at a time
and netsuite isnt going to allow a script to use an unlimited number of connections
so there is a limit, and probably a small limit of 1 or 2 per script
async code isnt faster because it allows you to consume more resources
its faster since it allows you to more efficiently use resources, in this case, instead of waiting for the search to finish, do something else instead
if there is no something else, it isnt faster
💯 1
e
Not questioning why the connections would be limited. Our expectation was that the Promise architecture would allow us to run multiple queries concurrently rather than serially, which would make the overall code faster because we have several "something elses" running at near the same time instead of waiting one after the other.
l
Is there any way to fetch all of the results from a paginated search asynchronously, or all they all loaded with search.load?
e
If there are too many results for the Restlet to handle in a timely manner, then you'll have to kick it to a Map/Reduce, which could handle the results or pages concurrently, but the client of your restlet would probably need some way to receive data from NetSuite to close the loop