Re-use an empty deck to save on creation time.
This commit is contained in:
parent
3b20de173f
commit
827bb84418
@ -9,7 +9,24 @@ def assertException(exception, func):
|
||||
found = True
|
||||
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")
|
||||
os.unlink(nam)
|
||||
return aopen(nam, **kwargs)
|
||||
|
@ -5,7 +5,7 @@ import nose, os, shutil, time
|
||||
from anki import Collection as aopen, Collection
|
||||
from anki.utils import intTime
|
||||
from anki.sync import Syncer, LocalServer
|
||||
from tests.shared import getEmptyDeck
|
||||
from tests.shared import getEmptyDeck, getEmptyDeckWith
|
||||
|
||||
# Local tests
|
||||
##########################################################################
|
||||
@ -26,7 +26,7 @@ def setup_basic():
|
||||
# answer it
|
||||
deck1.reset(); deck1.sched.answerCard(deck1.sched.getCard(), 4)
|
||||
# repeat for deck2
|
||||
deck2 = getEmptyDeck(server=True)
|
||||
deck2 = getEmptyDeckWith(server=True)
|
||||
f = deck2.newNote()
|
||||
f['Front'] = u"bar"; f['Back'] = u"bar"; f.tags = [u"bar"]
|
||||
deck2.addNote(f)
|
||||
@ -325,7 +325,7 @@ def _test_speed():
|
||||
deck1.tags.tags[tx] = -1
|
||||
deck1._usn = -1
|
||||
deck1.save()
|
||||
deck2 = getEmptyDeck(server=True)
|
||||
deck2 = getEmptyDeckWith(server=True)
|
||||
deck1.scm = deck2.scm = 0
|
||||
server = LocalServer(deck2)
|
||||
client = Syncer(deck1, server)
|
||||
|
Loading…
Reference in New Issue
Block a user