mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Re-use an empty deck to save on creation time.
This commit is contained in:
parent
3b20de173f
commit
827bb84418
2 changed files with 21 additions and 4 deletions
|
@ -9,7 +9,24 @@ def assertException(exception, func):
|
||||||
found = True
|
found = True
|
||||||
assert found
|
assert found
|
||||||
|
|
||||||
def getEmptyDeck(**kwargs):
|
|
||||||
|
# Creating new decks is expensive. Just do it once, and then spin off
|
||||||
|
# copies from the master.
|
||||||
|
def getEmptyDeck():
|
||||||
|
if len(getEmptyDeck.master) == 0:
|
||||||
|
(fd, nam) = tempfile.mkstemp(suffix=".anki2")
|
||||||
|
os.unlink(nam)
|
||||||
|
col = aopen(nam)
|
||||||
|
col.db.close()
|
||||||
|
getEmptyDeck.master = nam
|
||||||
|
(fd, nam) = tempfile.mkstemp(suffix=".anki2")
|
||||||
|
shutil.copy(getEmptyDeck.master, nam)
|
||||||
|
return aopen(nam)
|
||||||
|
|
||||||
|
getEmptyDeck.master = ""
|
||||||
|
|
||||||
|
# Fallback for when the DB needs options passed in.
|
||||||
|
def getEmptyDeckWith(**kwargs):
|
||||||
(fd, nam) = tempfile.mkstemp(suffix=".anki2")
|
(fd, nam) = tempfile.mkstemp(suffix=".anki2")
|
||||||
os.unlink(nam)
|
os.unlink(nam)
|
||||||
return aopen(nam, **kwargs)
|
return aopen(nam, **kwargs)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import nose, os, shutil, time
|
||||||
from anki import Collection as aopen, Collection
|
from anki import Collection as aopen, Collection
|
||||||
from anki.utils import intTime
|
from anki.utils import intTime
|
||||||
from anki.sync import Syncer, LocalServer
|
from anki.sync import Syncer, LocalServer
|
||||||
from tests.shared import getEmptyDeck
|
from tests.shared import getEmptyDeck, getEmptyDeckWith
|
||||||
|
|
||||||
# Local tests
|
# Local tests
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -26,7 +26,7 @@ def setup_basic():
|
||||||
# answer it
|
# answer it
|
||||||
deck1.reset(); deck1.sched.answerCard(deck1.sched.getCard(), 4)
|
deck1.reset(); deck1.sched.answerCard(deck1.sched.getCard(), 4)
|
||||||
# repeat for deck2
|
# repeat for deck2
|
||||||
deck2 = getEmptyDeck(server=True)
|
deck2 = getEmptyDeckWith(server=True)
|
||||||
f = deck2.newNote()
|
f = deck2.newNote()
|
||||||
f['Front'] = u"bar"; f['Back'] = u"bar"; f.tags = [u"bar"]
|
f['Front'] = u"bar"; f['Back'] = u"bar"; f.tags = [u"bar"]
|
||||||
deck2.addNote(f)
|
deck2.addNote(f)
|
||||||
|
@ -325,7 +325,7 @@ def _test_speed():
|
||||||
deck1.tags.tags[tx] = -1
|
deck1.tags.tags[tx] = -1
|
||||||
deck1._usn = -1
|
deck1._usn = -1
|
||||||
deck1.save()
|
deck1.save()
|
||||||
deck2 = getEmptyDeck(server=True)
|
deck2 = getEmptyDeckWith(server=True)
|
||||||
deck1.scm = deck2.scm = 0
|
deck1.scm = deck2.scm = 0
|
||||||
server = LocalServer(deck2)
|
server = LocalServer(deck2)
|
||||||
client = Syncer(deck1, server)
|
client = Syncer(deck1, server)
|
||||||
|
|
Loading…
Reference in a new issue