Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
Frank R.15
9 years agoHelpful | Level 5
API v2 - Long polling
I'm in the process of migrating from the V1 Sync API to the V2 "DIY" API and I would really appreciate some feedback on whether I'm really approaching this correctly, especially with regards to react...
- 9 years ago
Hi Frank, I'll be happy to help here.
"Question 1: Is this really the most efficient way that this can be done?"
Reading through your description (thank you for the detailed write up, it really helps), I believe there are a few optimizations to make:
a) "does a files.listFolder" ... "files.listFolderContinue" ... "then for each file it does a files.getMetaData and compares the rev":
If you've already done files.listFolder/files.listFolderContinue, you don't also need to call files.getMetadata for each file. That just returns the same Metadata objects as were already returned in ListFolderResult.entries from files.listFolder/files.listFolderContinue.
Part of the confusion may be that you need to cast the Metadata to e.g., FileMetadata to access FileMetadata.rev though, as shown here.
b) "if an updates occurs it restarts the entire sync process":
You don't need to start totally over. When files.listFolderLongPoll indicates something changed, you should just call back to files.listFolderContinue with the latest cursor you recieved, and it will tell you only about what has changed since then. (You should just continue applying the same steps from the files.listFolder documentation to apply those additional changes to your local state to get up to date.)
"Question 2: Is there are way of polling only for changes to a specific directory?"
No, unfortunately files.listFolderLongPoll will notify of changes in the account even if the changes only occurred outside of the path originally specified in the path set in the original files.listFolder call. We'll consider that a feature request, but I don't know if/when that would be implemented. (It would be non-trivial due to the way these pieces of infrastructure work on the backend.)
Hope this helps, and thanks for the kind words about the support!
Greg-DB
Dropbox Community Moderator
9 years agoHi Frank, I'll be happy to help here.
"Question 1: Is this really the most efficient way that this can be done?"
Reading through your description (thank you for the detailed write up, it really helps), I believe there are a few optimizations to make:
a) "does a files.listFolder" ... "files.listFolderContinue" ... "then for each file it does a files.getMetaData and compares the rev":
If you've already done files.listFolder/files.listFolderContinue, you don't also need to call files.getMetadata for each file. That just returns the same Metadata objects as were already returned in ListFolderResult.entries from files.listFolder/files.listFolderContinue.
Part of the confusion may be that you need to cast the Metadata to e.g., FileMetadata to access FileMetadata.rev though, as shown here.
b) "if an updates occurs it restarts the entire sync process":
You don't need to start totally over. When files.listFolderLongPoll indicates something changed, you should just call back to files.listFolderContinue with the latest cursor you recieved, and it will tell you only about what has changed since then. (You should just continue applying the same steps from the files.listFolder documentation to apply those additional changes to your local state to get up to date.)
"Question 2: Is there are way of polling only for changes to a specific directory?"
No, unfortunately files.listFolderLongPoll will notify of changes in the account even if the changes only occurred outside of the path originally specified in the path set in the original files.listFolder call. We'll consider that a feature request, but I don't know if/when that would be implemented. (It would be non-trivial due to the way these pieces of infrastructure work on the backend.)
Hope this helps, and thanks for the kind words about the support!
Frank R.15
9 years agoHelpful | Level 5
Cheers, that's awesome and makes a lot of sense. I did miss the metadata casting and did wonder "why on earth bother sending back metadata at all if the revision isn't in there?"
I'm getting rid of code left, right and center and getting better performance into the bargain.
I'm so glad I posted here!
Cheers,
Frank
I'm getting rid of code left, right and center and getting better performance into the bargain.
I'm so glad I posted here!
Cheers,
Frank
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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!