The current code calls twice NuxeoDrive.ScrollDescendants for each and every folder.
It will call it the first time to get (at most) N descendants and recall it until it's empty.
If a folder A contains 10 text files, the operation will be called once, and retrieve the 10 descendants. Then the operation will be called again, and retrieve no descendants, so the loop will stop. This amounts to 2 calls to the server.
However, we know that we ask for 100-item pages, so by receiving only 10 descendants, we know we won't get more on the next call, so we could stop at only 1 call.
It can be optimized by finishing the scroll if the number of descendants received is less than N.
Here, N is hard coded to 100. We will move it to the BATCH_SIZE constant.
In theory, it will make one less call to the server per-folder. If on average, folders have less than BATCH_SIZE documents inside them, it will essentially divide the amount of calls to the server by 2 for this operation.