mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
after a save, revert to unmodified state; sync tweaks
This commit is contained in:
parent
cdb33cf6a8
commit
9d5357f7a6
6 changed files with 26 additions and 0 deletions
|
@ -88,6 +88,13 @@ conf, models, decks, dconf, tags from col""")
|
|||
self.decks.load(decks, dconf)
|
||||
self.tags.load(tags)
|
||||
|
||||
def setMod(self):
|
||||
"""Mark DB modified.
|
||||
|
||||
DB operations and the deck/tag/model managers do this automatically, so this
|
||||
is only necessary if you modify properties of this object or the conf dict."""
|
||||
self.db.mod = True
|
||||
|
||||
def flush(self, mod=None):
|
||||
"Flush state to DB, updating mod time."
|
||||
self.mod = intTime(1000) if mod is None else mod
|
||||
|
@ -108,6 +115,7 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
|||
self.flush(mod=mod)
|
||||
self.db.commit()
|
||||
self.lock()
|
||||
self.db.mod = False
|
||||
self._markOp(name)
|
||||
self._lastSave = time.time()
|
||||
|
||||
|
@ -117,7 +125,10 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
|||
self.save()
|
||||
|
||||
def lock(self):
|
||||
# make sure we don't accidentally bump mod time
|
||||
mod = self.db.mod
|
||||
self.db.execute("update col set mod=mod")
|
||||
self.db.mod = mod
|
||||
|
||||
def close(self, save=True):
|
||||
"Disconnect from DB."
|
||||
|
|
|
@ -104,6 +104,7 @@ class DeckManager(object):
|
|||
self.col.db.execute("update col set decks=?, dconf=?",
|
||||
simplejson.dumps(self.decks),
|
||||
simplejson.dumps(self.dconf))
|
||||
self.changed = False
|
||||
|
||||
# Deck save/load
|
||||
#############################################################
|
||||
|
|
|
@ -80,6 +80,7 @@ class ModelManager(object):
|
|||
if self.changed:
|
||||
self.col.db.execute("update col set models = ?",
|
||||
simplejson.dumps(self.models))
|
||||
self.changed = False
|
||||
|
||||
# Retrieving and creating models
|
||||
#############################################################
|
||||
|
|
|
@ -37,6 +37,9 @@ class Syncer(object):
|
|||
|
||||
def sync(self):
|
||||
"Returns 'noChanges', 'fullSync', or 'success'."
|
||||
# if the deck has any pending changes, flush them first and bump mod
|
||||
# time
|
||||
self.col.save()
|
||||
# step 1: login & metadata
|
||||
runHook("sync", "login")
|
||||
ret = self.server.meta()
|
||||
|
@ -135,7 +138,9 @@ select count() from notes where id not in (select distinct nid from cards)""")
|
|||
assert usn != -1
|
||||
for m in self.col.models.all():
|
||||
assert m['usn'] != -1
|
||||
self.col.sched.reset()
|
||||
return [
|
||||
self.col.sched.repCounts(),
|
||||
self.col.db.scalar("select count() from cards"),
|
||||
self.col.db.scalar("select count() from notes"),
|
||||
self.col.db.scalar("select count() from revlog"),
|
||||
|
|
|
@ -29,6 +29,7 @@ class TagManager(object):
|
|||
if self.changed:
|
||||
self.col.db.execute("update col set tags=?",
|
||||
simplejson.dumps(self.tags))
|
||||
self.changed = False
|
||||
|
||||
# Registering and fetching tags
|
||||
#############################################################
|
||||
|
|
|
@ -47,6 +47,7 @@ def setup_basic():
|
|||
def setup_modified():
|
||||
setup_basic()
|
||||
# mark deck1 as changed
|
||||
deck1.setMod()
|
||||
deck1.save()
|
||||
|
||||
@nose.with_setup(setup_basic)
|
||||
|
@ -56,6 +57,7 @@ def test_nochange():
|
|||
@nose.with_setup(setup_modified)
|
||||
def test_changedSchema():
|
||||
deck1.scm += 1
|
||||
deck1.setMod()
|
||||
assert client.sync() == "fullSync"
|
||||
|
||||
@nose.with_setup(setup_modified)
|
||||
|
@ -84,6 +86,7 @@ def test_sync():
|
|||
assert client.sync() == "noChanges"
|
||||
# if we bump mod time, everything is copied across again because of the
|
||||
# 600 second sync leeway. but the decks should remain the same.
|
||||
deck1.setMod()
|
||||
deck1.save()
|
||||
assert client.sync() == "success"
|
||||
check(2)
|
||||
|
@ -168,6 +171,7 @@ def test_tags():
|
|||
deck2.tags.register(["xyz"])
|
||||
assert deck1.tags.all() != deck2.tags.all()
|
||||
deck1.save()
|
||||
time.sleep(0.1)
|
||||
deck2.save()
|
||||
assert client.sync() == "success"
|
||||
assert deck1.tags.all() == deck2.tags.all()
|
||||
|
@ -182,6 +186,7 @@ def test_decks():
|
|||
time.sleep(0.1)
|
||||
deck2.decks.id("new2")
|
||||
deck1.save()
|
||||
time.sleep(0.1)
|
||||
deck2.save()
|
||||
assert client.sync() == "success"
|
||||
assert deck1.tags.all() == deck2.tags.all()
|
||||
|
@ -199,6 +204,7 @@ def test_conf():
|
|||
test_sync()
|
||||
assert deck2.conf['topDeck'] == 1
|
||||
deck1.conf['topDeck'] = 2
|
||||
deck1.setMod()
|
||||
deck1.save()
|
||||
assert client.sync() == "success"
|
||||
assert deck2.conf['topDeck'] == 2
|
||||
|
@ -221,6 +227,7 @@ def test_threeway():
|
|||
deck1.save()
|
||||
# at time 2, client 2 syncs to server
|
||||
time.sleep(1)
|
||||
deck3.setMod()
|
||||
deck3.save()
|
||||
assert client2.sync() == "success"
|
||||
# at time 3, client 1 syncs, adding the older note
|
||||
|
|
Loading…
Reference in a new issue