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"
|
tbls = "notes", "cards", "revlog", "graves"
|
||||||
for t in tbls:
|
for t in tbls:
|
||||||
self.db.execute("update %s set usn=0 where usn=-1" % t)
|
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.modSchema()
|
||||||
self.ls = self.scm
|
self.ls = self.scm
|
||||||
self.close()
|
self.close()
|
||||||
|
|
|
@ -266,10 +266,10 @@ class DeckManager(object):
|
||||||
"update cards set did=?,usn=?,mod=? where id in "+
|
"update cards set did=?,usn=?,mod=? where id in "+
|
||||||
ids2str(cids), did, self.col.usn(), intTime())
|
ids2str(cids), did, self.col.usn(), intTime())
|
||||||
|
|
||||||
|
|
||||||
def maybeAddToActive(self):
|
def maybeAddToActive(self):
|
||||||
# since order is important, we can't just append to the end
|
# reselect current deck, or default if current has disappeared
|
||||||
self.select(self.selected())
|
c = self.current()
|
||||||
|
self.select(c['id'])
|
||||||
|
|
||||||
def sendHome(self, cids):
|
def sendHome(self, cids):
|
||||||
self.col.db.execute("""
|
self.col.db.execute("""
|
||||||
|
@ -334,3 +334,13 @@ usn=?,mod=? where id in %s""" % ids2str(cids),
|
||||||
"The top level did for NAME."
|
"The top level did for NAME."
|
||||||
path = name.split("::")
|
path = name.split("::")
|
||||||
return self.id(path[0])
|
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:
|
if ok:
|
||||||
avail.append(ord)
|
avail.append(ord)
|
||||||
return avail
|
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")
|
runHook("sync", "sanity")
|
||||||
c = self.sanityCheck()
|
c = self.sanityCheck()
|
||||||
s = self.server.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
|
# finalize
|
||||||
runHook("sync", "finalize")
|
runHook("sync", "finalize")
|
||||||
mod = self.server.finish()
|
mod = self.server.finish()
|
||||||
|
@ -192,8 +194,7 @@ from notes where %s""" % d)
|
||||||
|
|
||||||
def chunk(self):
|
def chunk(self):
|
||||||
buf = dict(done=False)
|
buf = dict(done=False)
|
||||||
# gather up to 5000 records
|
lim = 2500
|
||||||
lim = 5000
|
|
||||||
while self.tablesLeft and lim:
|
while self.tablesLeft and lim:
|
||||||
curTable = self.tablesLeft[0]
|
curTable = self.tablesLeft[0]
|
||||||
if not self.cursor:
|
if not self.cursor:
|
||||||
|
@ -249,11 +250,16 @@ from notes where %s""" % d)
|
||||||
return dict(cards=cards, notes=notes, decks=decks)
|
return dict(cards=cards, notes=notes, decks=decks)
|
||||||
|
|
||||||
def mergeGraves(self, graves):
|
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
|
# notes first, so we don't end up with duplicate graves
|
||||||
self.col._remNotes(graves['notes'])
|
self.col._remNotes(graves['notes'])
|
||||||
|
# then cards and decks
|
||||||
self.col.remCards(graves['cards'])
|
self.col.remCards(graves['cards'])
|
||||||
for oid in graves['decks']:
|
for oid in graves['decks']:
|
||||||
self.col.decks.rem(oid)
|
self.col.decks.rem(oid)
|
||||||
|
self.col.server = server
|
||||||
|
|
||||||
# Models
|
# Models
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
@ -177,3 +177,11 @@ class TagManager(object):
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"update cards set did=?,mod=?,usn=? where nid in "+ids2str(nids),
|
"update cards set did=?,mod=?,usn=? where nid in "+ids2str(nids),
|
||||||
did, intTime(), self.col.usn())
|
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