<@U5H9HECTS> I think `getRange()` is the easiest. ...
# suitescript
s
@screnshaw I think
getRange()
is the easiest. I confirmed with NS support that there should be no performance difference between successive
getRange()
calls and the native
runPaged()
alternative
s
Yeah, I've been using getRange. It just takes forever to return even 20,000 results. If I get much more than that, it'll start timing out.
a
20,000 results mean processing 20,000 search/result objects, they are not small...
s
shouldn't be that much. It's just a query on the db. sql queries can load a whole lot more than that almost instantly
also only returning a small number of columns
s
if you can use a lazy processing approach it doesn't matter if they are small or not since you'd only hold a single page of results in memory at any given time
NFT-SS1 lazy search does that, and I'm about to add the same sort of behavior (via a different lib) to NFT-SS2 because it's so handy
r
You could also load specific lines (i.e filter out the unwanted lines) with formulas
Loading 20k results, even if you only load specific columns seems like alot
s
I think it's safe to assume that he needs all those results. Most often though I find i'm processing one result at a time. So if you keep even a max page (1000) you only have 1000 to worry about in memory.
with scheduled scripts, the most common and simple pattern we use to process 1 million results is something like
Copy code
`
lazy.loadSearch(1234)
.nsSearchResult2obj()
.takeWhile(governanceRemains)
.each( /*... do something here*. )
s
Nice. Doesn't the search.run() already lazy load though?
s
it does in the sense that you have to ask for pages of data
the key is to abstract yourself from managing and asking for the pages - that code snippet above doesn't change whether there's 1 result or 1 million
though the snippet above is more lazy in that each successive operation chained is only called as each individual result is processed, unlike lodash that creates copies of intermediate results.
s
is that querying the db directly via nft or just calling the search.run() stuff?
s
NFT calls search.run() and getRange() behind the scenes, and surfaces a truly lazy sequence that processes results one at a time
for example, if you used standard lodash.map() and passed it 1000 results, it will return 1000 new results. So you have in memory now 2000 objects. Each time you do an operation you get a new array of results - that's eager evaluation. Long story short is NFT uses lazy evaluation even in the javascript processing, not just database access.