mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
tell server which files we need
This commit is contained in:
parent
7b217c63fe
commit
dceacff47c
2 changed files with 20 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
files = self.server.mediaList()
|
||||
self.col.media.removeExisting(files)
|
||||
if not lusn:
|
||||
files = self.server.mediaList()
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue