tell server which files we need

This commit is contained in:
Damien Elmes 2013-05-27 15:29:24 +09:00
parent 7b217c63fe
commit dceacff47c
2 changed files with 20 additions and 8 deletions

View file

@ -474,9 +474,18 @@ create table log (fname text primary key, type int);
self.db.commit()
def removeExisting(self, files):
"Remove files from list of files to sync."
# add temporary index
self.db.execute("create index if not exists ix_fname_tmp on log(fname)")
self.db.executemany("delete from log where fname=?", ((f,) for f in files))
self.db.execute("drop index ix_fname_tmp")
"Remove files from list of files to sync, and return missing files."
need = []
remove = []
for f in files:
if self.db.execute("select 1 from log where fname=?", f):
remove.append((f,))
else:
need.append(f)
self.db.executemany("delete from log where fname=?", remove)
self.db.commit()
# if we need all the server files, it's faster to pass None than
# the full list
if need and len(files) == len(need):
return None
return need

View file

@ -665,8 +665,11 @@ class MediaSyncer(object):
return "noChanges"
# step 1.5: if resyncing, we need to get the list of files the server
# has and remove them from our local list of files to sync
if not lusn:
files = self.server.mediaList()
self.col.media.removeExisting(files)
need = self.col.media.removeExisting(files)
else:
need = None
# step 2: send/recv deletions
runHook("sync", "removeMedia")
lrem = self.removed()
@ -677,7 +680,7 @@ class MediaSyncer(object):
while 1:
runHook("sync", "streamMedia")
usn = self.col.media.usn()
zip = self.server.files(minUsn=usn)
zip = self.server.files(minUsn=usn, need=need)
if self.addFiles(zip=zip):
break
# step 4: stream files to the server