mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -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(
|
return self.db.scalar(
|
||||||
"select count() from media where csum is not null")
|
"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):
|
def forceResync(self):
|
||||||
self.db.execute("delete from media")
|
self.db.execute("delete from media")
|
||||||
self.db.execute("update meta set lastUsn=0,dirMod=0")
|
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 anki.consts import *
|
||||||
from hooks import runHook
|
from hooks import runHook
|
||||||
import anki
|
import anki
|
||||||
|
from lang import ngettext
|
||||||
|
|
||||||
# syncing vars
|
# syncing vars
|
||||||
HTTP_TIMEOUT = 90
|
HTTP_TIMEOUT = 90
|
||||||
|
@ -789,11 +790,16 @@ class MediaSyncer(object):
|
||||||
# and we need to send our own
|
# and we need to send our own
|
||||||
|
|
||||||
updateConflict = False
|
updateConflict = False
|
||||||
|
toSend = self.col.media.dirtyCount()
|
||||||
while True:
|
while True:
|
||||||
zip, fnames = self.col.media.mediaChangesZip()
|
zip, fnames = self.col.media.mediaChangesZip()
|
||||||
if not fnames:
|
if not fnames:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
runHook("syncMsg", ngettext(
|
||||||
|
"%d media change to upload", "%d media changes to upload", toSend)
|
||||||
|
% toSend)
|
||||||
|
|
||||||
processedCnt, serverLastUsn = self.server.uploadChanges(zip)
|
processedCnt, serverLastUsn = self.server.uploadChanges(zip)
|
||||||
self.col.media.markClean(fnames[0:processedCnt])
|
self.col.media.markClean(fnames[0:processedCnt])
|
||||||
|
|
||||||
|
@ -811,6 +817,8 @@ class MediaSyncer(object):
|
||||||
self.col.media.db.commit()
|
self.col.media.db.commit()
|
||||||
updateConflict = True
|
updateConflict = True
|
||||||
|
|
||||||
|
toSend -= processedCnt
|
||||||
|
|
||||||
if updateConflict:
|
if updateConflict:
|
||||||
self.col.log("restart sync due to concurrent update")
|
self.col.log("restart sync due to concurrent update")
|
||||||
return self.sync()
|
return self.sync()
|
||||||
|
@ -826,6 +834,11 @@ class MediaSyncer(object):
|
||||||
def _downloadFiles(self, fnames):
|
def _downloadFiles(self, fnames):
|
||||||
self.col.log("%d files to fetch"%len(fnames))
|
self.col.log("%d files to fetch"%len(fnames))
|
||||||
while 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]
|
top = fnames[0:SYNC_ZIP_COUNT]
|
||||||
self.col.log("fetch %s"%top)
|
self.col.log("fetch %s"%top)
|
||||||
zipData = self.server.downloadFiles(files=top)
|
zipData = self.server.downloadFiles(files=top)
|
||||||
|
|
|
@ -116,6 +116,9 @@ Please visit AnkiWeb, upgrade your deck, then try again."""))
|
||||||
if m:
|
if m:
|
||||||
self.label = m
|
self.label = m
|
||||||
self._updateLabel()
|
self._updateLabel()
|
||||||
|
elif evt == "syncMsg":
|
||||||
|
self.label = args[0]
|
||||||
|
self._updateLabel()
|
||||||
elif evt == "error":
|
elif evt == "error":
|
||||||
self._didError = True
|
self._didError = True
|
||||||
showText(_("Syncing failed:\n%s")%
|
showText(_("Syncing failed:\n%s")%
|
||||||
|
@ -296,6 +299,8 @@ class SyncThread(QThread):
|
||||||
self.byteUpdate = time.time()
|
self.byteUpdate = time.time()
|
||||||
def syncEvent(type):
|
def syncEvent(type):
|
||||||
self.fireEvent("sync", type)
|
self.fireEvent("sync", type)
|
||||||
|
def syncMsg(msg):
|
||||||
|
self.fireEvent("syncMsg", msg)
|
||||||
def canPost():
|
def canPost():
|
||||||
if (time.time() - self.byteUpdate) > 0.1:
|
if (time.time() - self.byteUpdate) > 0.1:
|
||||||
self.byteUpdate = time.time()
|
self.byteUpdate = time.time()
|
||||||
|
@ -309,6 +314,7 @@ class SyncThread(QThread):
|
||||||
if canPost():
|
if canPost():
|
||||||
self.fireEvent("recv", self.recvTotal)
|
self.fireEvent("recv", self.recvTotal)
|
||||||
addHook("sync", syncEvent)
|
addHook("sync", syncEvent)
|
||||||
|
addHook("syncMsg", syncMsg)
|
||||||
addHook("httpSend", sendEvent)
|
addHook("httpSend", sendEvent)
|
||||||
addHook("httpRecv", recvEvent)
|
addHook("httpRecv", recvEvent)
|
||||||
# run sync and catch any errors
|
# run sync and catch any errors
|
||||||
|
@ -323,6 +329,7 @@ class SyncThread(QThread):
|
||||||
# don't bump mod time unless we explicitly save
|
# don't bump mod time unless we explicitly save
|
||||||
self.col.close(save=False)
|
self.col.close(save=False)
|
||||||
remHook("sync", syncEvent)
|
remHook("sync", syncEvent)
|
||||||
|
remHook("syncMsg", syncMsg)
|
||||||
remHook("httpSend", sendEvent)
|
remHook("httpSend", sendEvent)
|
||||||
remHook("httpRecv", recvEvent)
|
remHook("httpRecv", recvEvent)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue