mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 00:12:25 -04:00
display more feedback when syncing media
deletes in particular take some time for the server to process, but don't require much bandwidth, leading to the progress appearing to have pause when content is actually being processed this also gives the user an idea of how long the process will take to complete
This commit is contained in:
parent
f5d60c70e2
commit
cf801e4fb4
3 changed files with 24 additions and 0 deletions
|
@ -439,6 +439,10 @@ create table meta (dirMod int, lastUsn int); insert into meta values (0, 0);
|
|||
return self.db.scalar(
|
||||
"select count() from media where csum is not null")
|
||||
|
||||
def dirtyCount(self):
|
||||
return self.db.scalar(
|
||||
"select count() from media where dirty=1")
|
||||
|
||||
def forceResync(self):
|
||||
self.db.execute("delete from media")
|
||||
self.db.execute("update meta set lastUsn=0,dirMod=0")
|
||||
|
|
13
anki/sync.py
13
anki/sync.py
|
@ -14,6 +14,7 @@ from anki.utils import ids2str, intTime, json, isWin, isMac, platDesc, checksum
|
|||
from anki.consts import *
|
||||
from hooks import runHook
|
||||
import anki
|
||||
from lang import ngettext
|
||||
|
||||
# syncing vars
|
||||
HTTP_TIMEOUT = 90
|
||||
|
@ -789,11 +790,16 @@ class MediaSyncer(object):
|
|||
# and we need to send our own
|
||||
|
||||
updateConflict = False
|
||||
toSend = self.col.media.dirtyCount()
|
||||
while True:
|
||||
zip, fnames = self.col.media.mediaChangesZip()
|
||||
if not fnames:
|
||||
break
|
||||
|
||||
runHook("syncMsg", ngettext(
|
||||
"%d media change to upload", "%d media changes to upload", toSend)
|
||||
% toSend)
|
||||
|
||||
processedCnt, serverLastUsn = self.server.uploadChanges(zip)
|
||||
self.col.media.markClean(fnames[0:processedCnt])
|
||||
|
||||
|
@ -811,6 +817,8 @@ class MediaSyncer(object):
|
|||
self.col.media.db.commit()
|
||||
updateConflict = True
|
||||
|
||||
toSend -= processedCnt
|
||||
|
||||
if updateConflict:
|
||||
self.col.log("restart sync due to concurrent update")
|
||||
return self.sync()
|
||||
|
@ -826,6 +834,11 @@ class MediaSyncer(object):
|
|||
def _downloadFiles(self, fnames):
|
||||
self.col.log("%d files to fetch"%len(fnames))
|
||||
while fnames:
|
||||
n = len(fnames)
|
||||
runHook("syncMsg", ngettext(
|
||||
"%d media file to download", "%d media files to download", n)
|
||||
% n)
|
||||
|
||||
top = fnames[0:SYNC_ZIP_COUNT]
|
||||
self.col.log("fetch %s"%top)
|
||||
zipData = self.server.downloadFiles(files=top)
|
||||
|
|
|
@ -116,6 +116,9 @@ Please visit AnkiWeb, upgrade your deck, then try again."""))
|
|||
if m:
|
||||
self.label = m
|
||||
self._updateLabel()
|
||||
elif evt == "syncMsg":
|
||||
self.label = args[0]
|
||||
self._updateLabel()
|
||||
elif evt == "error":
|
||||
self._didError = True
|
||||
showText(_("Syncing failed:\n%s")%
|
||||
|
@ -296,6 +299,8 @@ class SyncThread(QThread):
|
|||
self.byteUpdate = time.time()
|
||||
def syncEvent(type):
|
||||
self.fireEvent("sync", type)
|
||||
def syncMsg(msg):
|
||||
self.fireEvent("syncMsg", msg)
|
||||
def canPost():
|
||||
if (time.time() - self.byteUpdate) > 0.1:
|
||||
self.byteUpdate = time.time()
|
||||
|
@ -309,6 +314,7 @@ class SyncThread(QThread):
|
|||
if canPost():
|
||||
self.fireEvent("recv", self.recvTotal)
|
||||
addHook("sync", syncEvent)
|
||||
addHook("syncMsg", syncMsg)
|
||||
addHook("httpSend", sendEvent)
|
||||
addHook("httpRecv", recvEvent)
|
||||
# run sync and catch any errors
|
||||
|
@ -323,6 +329,7 @@ class SyncThread(QThread):
|
|||
# don't bump mod time unless we explicitly save
|
||||
self.col.close(save=False)
|
||||
remHook("sync", syncEvent)
|
||||
remHook("syncMsg", syncMsg)
|
||||
remHook("httpSend", sendEvent)
|
||||
remHook("httpRecv", recvEvent)
|
||||
|
||||
|
|
Loading…
Reference in a new issue