cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Update latency for files_list_folder cursor

Update latency for files_list_folder cursor

RobinHarveyIW
Explorer | Level 4

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)

 

 

1 Reply 1

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)
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    RobinHarveyIW Explorer | Level 4
What do Dropbox user levels mean?