Skip to content

Commit

Permalink
improve performance
Browse files Browse the repository at this point in the history
reduce API rate delay;

restore_folder():
move delay to restore_file() in order to speed up case when no actual
	restore is done for unchanged files;
pass 'modified' time-stamp from folder listing to restore_file();

restore_file():
skip files which have not been changed since the cutoff date-time which
	saves the round-trip to determine that nothing has changed from
	the per-file history;
  • Loading branch information
tvogel committed May 11, 2016
1 parent 932db02 commit 13e7302
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions restore.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python
#!/usr/bin/env python2.7
import sys, os, dropbox, time
from datetime import datetime

APP_KEY = '' # INSERT APP_KEY HERE
APP_SECRET = '' # INSERT APP_SECRET HERE
DELAY = 0.2 # delay between each file (try to stay under API rate limits)
DELAY = 0.05 # delay between each file (try to stay under API rate limits)

HELP_MESSAGE = \
"""Note: You must specify the path starting with "/", where "/" is the root
Expand Down Expand Up @@ -48,7 +48,7 @@ def parse_date(s):
return datetime.strptime(a, '%a, %d %b %Y %H:%M:%S')


def restore_file(client, path, cutoff_datetime, is_deleted, verbose=False):
def restore_file(client, path, cutoff_datetime, is_deleted, mod_datetime, verbose=False):
global resume_path

if resume_path:
Expand All @@ -58,6 +58,10 @@ def restore_file(client, path, cutoff_datetime, is_deleted, verbose=False):
else:
print('Skipping ' + path)
return

if cutoff_datetime >= mod_datetime:
print('Skipping unchanged ' + path)
return

revisions = client.revisions(path.encode('utf8'))
current_rev = revisions[0]['rev']
Expand Down Expand Up @@ -104,6 +108,7 @@ def restore_file(client, path, cutoff_datetime, is_deleted, verbose=False):
print(path + ' ' + ('SKIP' if is_deleted else 'DELETE'))
if not is_deleted:
client.file_delete(path.encode('utf8'))
time.sleep(DELAY)


def restore_folder(client, path, cutoff_datetime, verbose=False):
Expand All @@ -127,8 +132,7 @@ def restore_folder(client, path, cutoff_datetime, verbose=False):
restore_folder(client, item['path'], cutoff_datetime, verbose)
else:
restore_file(client, item['path'], cutoff_datetime,
item.get('is_deleted', False), verbose)
time.sleep(DELAY)
item.get('is_deleted', False), parse_date(item.get('modified')), verbose)


def main():
Expand Down

0 comments on commit 13e7302

Please sign in to comment.