don't check sources on sync; let ankionline handle it instead

This commit is contained in:
Damien Elmes 2010-10-19 19:59:47 +09:00
parent cdab5318d1
commit 8032c4a66b
2 changed files with 4 additions and 41 deletions

View file

@ -2160,7 +2160,7 @@ it to your friends.
########################################################################## ##########################################################################
def syncDeck(self, interactive=True, create=False, onlyMerge=False, def syncDeck(self, interactive=True, create=False, onlyMerge=False,
reload=True, checkSources=True): reload=True):
"Synchronise a deck with the server." "Synchronise a deck with the server."
if not self.inMainWindow() and interactive: return if not self.inMainWindow() and interactive: return
self.setNotice() self.setNotice()
@ -2185,7 +2185,6 @@ it to your friends.
# sync all decks # sync all decks
self.loadAfterSync = -1 self.loadAfterSync = -1
self.syncName = None self.syncName = None
self.sourcesToCheck = []
self.syncDecks = self.decksToSync() self.syncDecks = self.decksToSync()
else: else:
# sync one deck # sync one deck
@ -2199,13 +2198,6 @@ it to your friends.
self.deckPath = self.deck.path self.deckPath = self.deck.path
self.syncName = self.deck.syncName or self.deck.name() self.syncName = self.deck.syncName or self.deck.name()
self.lastSync = self.deck.lastSync self.lastSync = self.deck.lastSync
if checkSources:
self.sourcesToCheck = self.deck.s.column0(
"select id from sources where syncPeriod != -1 "
"and syncPeriod = 0 or :t - lastSync > syncPeriod",
t=time.time())
else:
self.sourcesToCheck = []
self.deck.close() self.deck.close()
self.deck = None self.deck = None
self.loadAfterSync = reload self.loadAfterSync = reload
@ -2215,7 +2207,7 @@ it to your friends.
import gc; gc.collect() import gc; gc.collect()
self.mainWin.welcomeText.setText(u"") self.mainWin.welcomeText.setText(u"")
self.syncThread = ui.sync.Sync(self, u, p, interactive, create, self.syncThread = ui.sync.Sync(self, u, p, interactive, create,
onlyMerge, self.sourcesToCheck) onlyMerge)
self.connect(self.syncThread, SIGNAL("setStatus"), self.setSyncStatus) self.connect(self.syncThread, SIGNAL("setStatus"), self.setSyncStatus)
self.connect(self.syncThread, SIGNAL("showWarning"), self.showSyncWarning) self.connect(self.syncThread, SIGNAL("showWarning"), self.showSyncWarning)
self.connect(self.syncThread, SIGNAL("noSyncResponse"), self.noSyncResponse) self.connect(self.syncThread, SIGNAL("noSyncResponse"), self.noSyncResponse)

View file

@ -20,7 +20,7 @@ from anki.hooks import addHook, removeHook
class Sync(QThread): class Sync(QThread):
def __init__(self, parent, user, pwd, interactive, create, def __init__(self, parent, user, pwd, interactive, create,
onlyMerge, sourcesToCheck): onlyMerge):
QThread.__init__(self) QThread.__init__(self)
self.parent = parent self.parent = parent
self.interactive = interactive self.interactive = interactive
@ -29,7 +29,6 @@ class Sync(QThread):
self.create = create self.create = create
self.ok = True self.ok = True
self.onlyMerge = onlyMerge self.onlyMerge = onlyMerge
self.sourcesToCheck = sourcesToCheck
self.proxy = None self.proxy = None
addHook('fullSyncStarted', self.fullSyncStarted) addHook('fullSyncStarted', self.fullSyncStarted)
addHook('fullSyncFinished', self.fullSyncFinished) addHook('fullSyncFinished', self.fullSyncFinished)
@ -92,7 +91,6 @@ sync was aborted. Please report this error.""")
if not self.proxy: if not self.proxy:
self.setStatus(_("Connecting..."), 0) self.setStatus(_("Connecting..."), 0)
proxy = HttpSyncServerProxy(self.user, self.pwd) proxy = HttpSyncServerProxy(self.user, self.pwd)
proxy.sourcesToCheck = self.sourcesToCheck
proxy.connect("ankiqt-" + ankiqt.appVersion) proxy.connect("ankiqt-" + ankiqt.appVersion)
self.proxy = proxy self.proxy = proxy
# check clock # check clock
@ -219,9 +217,6 @@ sync was aborted. Please report this error.""")
self.setStatus(_("Downloading..."), 0) self.setStatus(_("Downloading..."), 0)
client.fullSyncFromServer(ret[1], ret[2]) client.fullSyncFromServer(ret[1], ret[2])
self.setStatus(_("Sync complete."), 0) self.setStatus(_("Sync complete."), 0)
# reopen the deck in case we have sources
self.deck = DeckStorage.Deck(path)
client.deck = self.deck
else: else:
# diff # diff
self.setStatus(_("Determining differences..."), 0) self.setStatus(_("Determining differences..."), 0)
@ -244,35 +239,11 @@ sync was aborted. Please report this error.""")
changes = False changes = False
if not deck: if not deck:
self.setStatus(_("No changes found.")) self.setStatus(_("No changes found."))
# check sources
srcChanged = False
if self.sourcesToCheck:
start = time.time()
self.setStatus(_("<br><br>Checking deck subscriptions..."))
srcChanged = False
for source in self.sourcesToCheck:
proxy.deckName = str(source)
msg = "%s:" % client.syncOneWayDeckName()
if not proxy.hasDeck(str(source)):
self.setStatus(_(" * %s no longer exists.") % msg)
continue
if not client.prepareOneWaySync():
self.setStatus(_(" * %s no changes found.") % msg)
continue
srcChanged = True
self.setStatus(_(" * %s fetching payload...") % msg)
payload = proxy.genOneWayPayload(client.deck.lastSync)
self.setStatus(msg + _(" applied %d modified cards.") %
len(payload['cards']))
client.applyOneWayPayload(payload)
self.setStatus(_("Check complete."))
self.deck.s.flush()
self.deck.s.commit()
# close and send signal to main thread # close and send signal to main thread
self.deck.close() self.deck.close()
if not deck: if not deck:
taken = time.time() - start taken = time.time() - start
if (changes or srcChanged) and taken < 2.5: if changes and taken < 2.5:
time.sleep(2.5 - taken) time.sleep(2.5 - taken)
else: else:
time.sleep(0.25) time.sleep(0.25)