Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
tfrysinger
4 years agoExplorer | Level 4
searchContinueV2 seems to not work on the last batch it should find
I am using the Java2 SDK to perform a search for directories matching a pattern, then deleting them. The directories are named as:
ROOT_DIR_CONSTANT/p_<YYYYMMDD>/p_<ID 1>_<SUB ID 1>
For e...
Здравко
4 years agoLegendary | Level 20
tfrysinger wrote:
......
boolean keepGoin = true;
while (matches.size() > 0 && keepGoin) {
...What I am seeing is:
...6. Step 4 occurs and since result.getHasMore() returns true, the searchContinueV2() is called. However this time, while getHasMore() is set to FALSE within the returned result (which is correct), there is no entry in 'matches', i.e. it is empty. The third and final directory was not found! WHY NOT?
...
Hi tfrysinger,
Greg-DBhas explained what's the reason for 'there is no entry in', already. In addition, I would like to note the logical error in your code related to the loop. Why aren't you trying to fix it, instead of looking for alternatives? 🤔🤷
At any one moment the 'matches' could be empty, despite there are matching entries! In such a case what's going to happen? -> You will never get in the loop and your code wouldn't do anything, if that happens at the beginning or will stop 'looping' at first such moment (in your case at the last entry).
Reasonable question here is why you are using as a loop criteria unreliable values combination? There is always chance for a 'pause', which can confuse your code. Dropbox API (including all SDKs - Java in your case) performs asynchronous calls and they can NOT be predicted or forced ('batch size' is nothing more than a wish declaration, which server tries to and in most cases follows, but without guaranties)! You should be able make your code expect everything possible. That's it - everything possible is what's everything not impossible (including 'unusual' empty transaction - it's actually usual). Wouldn't it be easier to reformat loop criteria to something like:
...
while (matches.size() > 0 || result.getHasMore()) {
...... or similar? 🙂 Just a little logic inversion, so loop can't break processing in such a way anymore. Have you tried something like? 😉
Hope this gives direction.
- tfrysinger4 years agoExplorer | Level 4
Thanks but your suggestion wouldn't help in this case anyway. As Greg explained, the Search API isn't guaranteed to return the exact results due to indexing and caching. I didn't know that until his answer. And sure, I could optimize the loop with an OR statement instead of testing at the bottom but that really is just that - perhaps an improvement in readability but nothing that would solve the problem he brought up.
Instead, as he suggested, I will use listFolder to list to the level that I can, then iterate through to find and delete the relevant subdirs.
- Здравко4 years agoLegendary | Level 20
tfrysinger wrote:... And sure, I could optimize the loop with an OR statement instead of testing at the bottom but that really is just that - perhaps an improvement in readability but nothing that would solve the problem he brought up.
...Hmm... 😁 Are you sure it's something related to the "readability" only?! 😉 Yes, I'm not sure it will solve the issue (in particular), but it's definitely a BUG!!! Sleeping bug, able to "wake up" at some point, at least.
Be careful!
About Discuss Dropbox Developer and API
Explore Dropbox Developer & API discussions with developers like you.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!