mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
fix some sync bugs
- don't send server graves graves back on the next sync - make sure we update usns of models/tags/decks as well on upload - don't die when updating decks after current deck deleted - report counts when sanity check fails
This commit is contained in:
parent
52234f9d9a
commit
c0edcae238
5 changed files with 41 additions and 7 deletions
|
@ -198,7 +198,9 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
|||
tbls = "notes", "cards", "revlog", "graves"
|
||||
for t in tbls:
|
||||
self.db.execute("update %s set usn=0 where usn=-1" % t)
|
||||
self._usn = 0
|
||||
self.models.beforeUpload()
|
||||
self.tags.beforeUpload()
|
||||
self.decks.beforeUpload()
|
||||
self.modSchema()
|
||||
self.ls = self.scm
|
||||
self.close()
|
||||
|
|
|
@ -266,10 +266,10 @@ class DeckManager(object):
|
|||
"update cards set did=?,usn=?,mod=? where id in "+
|
||||
ids2str(cids), did, self.col.usn(), intTime())
|
||||
|
||||
|
||||
def maybeAddToActive(self):
|
||||
# since order is important, we can't just append to the end
|
||||
self.select(self.selected())
|
||||
# reselect current deck, or default if current has disappeared
|
||||
c = self.current()
|
||||
self.select(c['id'])
|
||||
|
||||
def sendHome(self, cids):
|
||||
self.col.db.execute("""
|
||||
|
@ -334,3 +334,13 @@ usn=?,mod=? where id in %s""" % ids2str(cids),
|
|||
"The top level did for NAME."
|
||||
path = name.split("::")
|
||||
return self.id(path[0])
|
||||
|
||||
# Sync handling
|
||||
##########################################################################
|
||||
|
||||
def beforeUpload(self):
|
||||
for d in self.all():
|
||||
d['usn'] = 0
|
||||
for c in self.allConf():
|
||||
c['usn'] = 0
|
||||
self.save()
|
||||
|
|
|
@ -483,3 +483,11 @@ select id from notes where mid = ?)""" % " ".join(map),
|
|||
if ok:
|
||||
avail.append(ord)
|
||||
return avail
|
||||
|
||||
# Sync handling
|
||||
##########################################################################
|
||||
|
||||
def beforeUpload(self):
|
||||
for m in self.all():
|
||||
m['usn'] = 0
|
||||
self.save()
|
||||
|
|
12
anki/sync.py
12
anki/sync.py
|
@ -80,7 +80,9 @@ class Syncer(object):
|
|||
runHook("sync", "sanity")
|
||||
c = self.sanityCheck()
|
||||
s = self.server.sanityCheck()
|
||||
assert c == s
|
||||
if c != s:
|
||||
raise Exception("""\
|
||||
Sanity check failed. Please copy and paste the text below:\n%s\n%s""" % (c, s))
|
||||
# finalize
|
||||
runHook("sync", "finalize")
|
||||
mod = self.server.finish()
|
||||
|
@ -192,8 +194,7 @@ from notes where %s""" % d)
|
|||
|
||||
def chunk(self):
|
||||
buf = dict(done=False)
|
||||
# gather up to 5000 records
|
||||
lim = 5000
|
||||
lim = 2500
|
||||
while self.tablesLeft and lim:
|
||||
curTable = self.tablesLeft[0]
|
||||
if not self.cursor:
|
||||
|
@ -249,11 +250,16 @@ from notes where %s""" % d)
|
|||
return dict(cards=cards, notes=notes, decks=decks)
|
||||
|
||||
def mergeGraves(self, graves):
|
||||
# make sure the deletions don't get a usn of -1k
|
||||
server = self.col.server
|
||||
self.col.server = True
|
||||
# notes first, so we don't end up with duplicate graves
|
||||
self.col._remNotes(graves['notes'])
|
||||
# then cards and decks
|
||||
self.col.remCards(graves['cards'])
|
||||
for oid in graves['decks']:
|
||||
self.col.decks.rem(oid)
|
||||
self.col.server = server
|
||||
|
||||
# Models
|
||||
##########################################################################
|
||||
|
|
|
@ -177,3 +177,11 @@ class TagManager(object):
|
|||
self.col.db.execute(
|
||||
"update cards set did=?,mod=?,usn=? where nid in "+ids2str(nids),
|
||||
did, intTime(), self.col.usn())
|
||||
|
||||
# Sync handling
|
||||
##########################################################################
|
||||
|
||||
def beforeUpload(self):
|
||||
for k in self.tags.keys():
|
||||
self.tags[k] = 0
|
||||
self.save()
|
||||
|
|
Loading…
Reference in a new issue