mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
fixed bug in bundling
This commit is contained in:
parent
667b89ecc5
commit
9fdfac722d
3 changed files with 29 additions and 11 deletions
|
@ -131,7 +131,7 @@ create table if not exists graves (
|
||||||
);
|
);
|
||||||
|
|
||||||
insert or ignore into deck
|
insert or ignore into deck
|
||||||
values(1,0,0,0,%(v)s,0,1,0,'','{}','','','{}');
|
values(1,0,0,0,%(v)s,0,0,0,'','{}','','','{}');
|
||||||
""" % ({'v':CURRENT_VERSION}))
|
""" % ({'v':CURRENT_VERSION}))
|
||||||
import anki.deck
|
import anki.deck
|
||||||
if setDeckConf:
|
if setDeckConf:
|
||||||
|
|
15
anki/sync.py
15
anki/sync.py
|
@ -58,6 +58,7 @@ class Syncer(object):
|
||||||
def sync(self):
|
def sync(self):
|
||||||
"Returns 'noChanges', 'fullSync', or 'success'."
|
"Returns 'noChanges', 'fullSync', or 'success'."
|
||||||
# step 1: login & metadata
|
# step 1: login & metadata
|
||||||
|
self.status("login")
|
||||||
self.rmod, rscm, self.maxUsn = self.server.times()
|
self.rmod, rscm, self.maxUsn = self.server.times()
|
||||||
self.lmod, lscm, self.minUsn = self.times()
|
self.lmod, lscm, self.minUsn = self.times()
|
||||||
if self.lmod == self.rmod:
|
if self.lmod == self.rmod:
|
||||||
|
@ -66,27 +67,34 @@ class Syncer(object):
|
||||||
return "fullSync"
|
return "fullSync"
|
||||||
self.lnewer = self.lmod > self.rmod
|
self.lnewer = self.lmod > self.rmod
|
||||||
# step 2: deletions and small objects
|
# step 2: deletions and small objects
|
||||||
|
self.status("meta")
|
||||||
lchg = self.changes()
|
lchg = self.changes()
|
||||||
rchg = self.server.applyChanges(
|
rchg = self.server.applyChanges(
|
||||||
minUsn=self.minUsn, lnewer=self.lnewer, changes=lchg)
|
minUsn=self.minUsn, lnewer=self.lnewer, changes=lchg)
|
||||||
self.mergeChanges(lchg, rchg)
|
self.mergeChanges(lchg, rchg)
|
||||||
# step 3: stream large tables from server
|
# step 3: stream large tables from server
|
||||||
|
self.status("server")
|
||||||
while 1:
|
while 1:
|
||||||
|
self.status("stream")
|
||||||
chunk = self.server.chunk()
|
chunk = self.server.chunk()
|
||||||
self.applyChunk(chunk)
|
self.applyChunk(chunk)
|
||||||
if chunk['done']:
|
if chunk['done']:
|
||||||
break
|
break
|
||||||
# step 4: stream to server
|
# step 4: stream to server
|
||||||
|
self.status("client")
|
||||||
while 1:
|
while 1:
|
||||||
|
self.status("stream")
|
||||||
chunk = self.chunk()
|
chunk = self.chunk()
|
||||||
self.server.applyChunk(chunk)
|
self.server.applyChunk(chunk)
|
||||||
if chunk['done']:
|
if chunk['done']:
|
||||||
break
|
break
|
||||||
# step 5: sanity check during beta testing
|
# step 5: sanity check during beta testing
|
||||||
|
self.status("sanity")
|
||||||
c = self.sanityCheck()
|
c = self.sanityCheck()
|
||||||
s = self.server.sanityCheck()
|
s = self.server.sanityCheck()
|
||||||
assert c == s
|
assert c == s
|
||||||
# finalize
|
# finalize
|
||||||
|
self.status("finalize")
|
||||||
mod = self.server.finish()
|
mod = self.server.finish()
|
||||||
self.finish(mod)
|
self.finish(mod)
|
||||||
return "success"
|
return "success"
|
||||||
|
@ -202,7 +210,8 @@ from facts where %s""" % d)
|
||||||
if not self.cursor:
|
if not self.cursor:
|
||||||
self.cursor = self.cursorForTable(curTable)
|
self.cursor = self.cursorForTable(curTable)
|
||||||
rows = self.cursor.fetchmany(lim)
|
rows = self.cursor.fetchmany(lim)
|
||||||
if len(rows) != lim:
|
fetched = len(rows)
|
||||||
|
if fetched != lim:
|
||||||
# table is empty
|
# table is empty
|
||||||
self.tablesLeft.pop(0)
|
self.tablesLeft.pop(0)
|
||||||
self.cursor = None
|
self.cursor = None
|
||||||
|
@ -212,7 +221,7 @@ from facts where %s""" % d)
|
||||||
"update %s set usn=? where usn=-1"%curTable,
|
"update %s set usn=? where usn=-1"%curTable,
|
||||||
self.maxUsn)
|
self.maxUsn)
|
||||||
buf[curTable] = rows
|
buf[curTable] = rows
|
||||||
lim -= len(buf)
|
lim -= fetched
|
||||||
if not self.tablesLeft:
|
if not self.tablesLeft:
|
||||||
buf['done'] = True
|
buf['done'] = True
|
||||||
return buf
|
return buf
|
||||||
|
@ -483,6 +492,8 @@ class HttpSyncServerProxy(object):
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# not yet ported
|
# not yet ported
|
||||||
|
|
||||||
|
# make sure it resets any usn == -1 before uploading!
|
||||||
|
|
||||||
class FullSyncer(object):
|
class FullSyncer(object):
|
||||||
|
|
||||||
def __init__(self, deck):
|
def __init__(self, deck):
|
||||||
|
|
|
@ -19,7 +19,7 @@ deck2=None
|
||||||
client=None
|
client=None
|
||||||
server=None
|
server=None
|
||||||
|
|
||||||
def setup_basic(loadDecks=None):
|
def setup_basic():
|
||||||
global deck1, deck2, client, server
|
global deck1, deck2, client, server
|
||||||
deck1 = getEmptyDeck()
|
deck1 = getEmptyDeck()
|
||||||
# add a fact to deck 1
|
# add a fact to deck 1
|
||||||
|
@ -231,14 +231,21 @@ def test_threeway():
|
||||||
|
|
||||||
def _test_speed():
|
def _test_speed():
|
||||||
t = time.time()
|
t = time.time()
|
||||||
setup_basic([os.path.expanduser("~/rapid.anki"),
|
deck1 = Deck(os.path.expanduser("~/rapid.anki"))
|
||||||
os.path.expanduser("~/rapid2.anki")])
|
for tbl in "revlog", "cards", "facts", "graves":
|
||||||
|
deck1.db.execute("update %s set usn = -1 where usn != -1"%tbl)
|
||||||
|
for m in deck1.models.all():
|
||||||
|
m['usn'] = -1
|
||||||
|
for tx in deck1.tags.all():
|
||||||
|
deck1.tags.tags[tx] = -1
|
||||||
|
deck1._usn = -1
|
||||||
|
deck1.save()
|
||||||
|
deck2 = getEmptyDeck(server=True)
|
||||||
|
deck1.scm = deck2.scm = 0
|
||||||
|
server = LocalServer(deck2)
|
||||||
|
client = Syncer(deck1, server)
|
||||||
print "load %d" % ((time.time() - t)*1000); t = time.time()
|
print "load %d" % ((time.time() - t)*1000); t = time.time()
|
||||||
deck2.save()
|
assert client.sync() == "success"
|
||||||
# 3000 revlog entries: ~128ms
|
|
||||||
# 3000 cards: ~200ms
|
|
||||||
# 3000 facts: ~500ms
|
|
||||||
assert client.sync() != "fullSync"
|
|
||||||
print "sync %d" % ((time.time() - t)*1000); t = time.time()
|
print "sync %d" % ((time.time() - t)*1000); t = time.time()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue