You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

RobinHarveyIW's avatar
RobinHarveyIW
Explorer | Level 4
4 years ago

Update latency for files_list_folder cursor

I'm trialing the simple polling method outlined here, and AFAICS it's taking a few hours for changes in my DB folders / files to be reflected in the results of files_list_folder and files_list_folder_continue.  Is this expected?  I was hoping that updates would be visible in API results in the seconds-to-minutes range, do I need to use a different API to get near this?

 

Here's my code, in case I've messed anything up 🙂

 

 

def poll_loop(client: DropboxClient,
              db_path: str,
              poll_freq: int,
              db_cursor: str = None):
    if db_cursor is None:
        list_result = client.files_list_folder(path=db_path, recursive=True)
    else:
        list_result = client.files_list_folder_continue(db_cursor)

    while True:
        log.info("scan files from cursor %s", list_result.cursor)
        while list_result.has_more:
            for entry in list_result.entries:
                log.info("scanned path: %s", entry.path_display)
            list_result = client.files_list_folder_continue(list_result.cursor)
            log.info("new cursor %s", list_result.cursor)
        if poll_freq == 0:
            return
        else:
            log.info("pause for %d seconds before next poll", poll_freq)
            time.sleep(poll_freq)
            list_result = client.files_list_folder_continue(list_result.cursor)
            log.info("new cursor %s", list_result.cursor)

 

 

  • RobinHarveyIW's avatar
    RobinHarveyIW
    Explorer | Level 4

    I figured out what the issue here was - it's the way my code was handling results pages and cursors.  I switched the loop control checks around a bit and it all started working fine:

    def poll_loop(client: DropboxClient,
                  db_path: str,
                  poll_freq: int,
                  db_cursor: str = None):
        if db_cursor is None:
            list_result = client.files_list_folder(path=db_path, recursive=True)
        else:
            list_result = client.files_list_folder_continue(db_cursor)
    
        while True:
            log.info("scan files from cursor %s", list_result.cursor)
            while list_result.entries:
                for entry in list_result.entries:
                    log.info("scanned path: %s", entry.path_display)
    
                if list_result.has_more:
                    list_result = client.files_list_folder_continue(list_result.cursor)
                    log.debug("new cursor %s", list_result.cursor)
                else:
                    log.debug("cursor is exhausted")
                    break
    
            if poll_freq == 0:
                log.info("final cursor: %s", list_result.cursor)
                return
            else:
                log.debug("pause for %d seconds before next poll", poll_freq)
                log.info("latest cursor: %s", list_result.cursor)
                time.sleep(poll_freq)
                list_result = client.files_list_folder_continue(list_result.cursor)

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,910 PostsLatest Activity: 3 days ago
333 Following

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 or Facebook.

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!