remove minimum average support

Calculating the average on startup is expensive on mobile devices. It might be
nice to provide it as a deck option or per-model setting in the future so that
people can specify how hard their material is and have it treated accordingly.
This commit is contained in:
Damien Elmes 2011-02-12 08:35:32 +09:00
parent 72a1cd73a9
commit 1a09aa9f77
2 changed files with 12 additions and 12 deletions

View file

@ -28,7 +28,7 @@ from anki.hooks import runHook, hookEmpty
from anki.template import render
from anki.media import updateMediaCount, mediaFiles, \
rebuildMediaDir
from anki.upgrade import upgradeSchema, updateIndices, upgradeDeck
from anki.upgrade import upgradeSchema, updateIndices, upgradeDeck, DECK_VERSION
import anki.latex # sets up hook
# ensure all the DB metadata in other files is loaded before proceeding
@ -57,7 +57,6 @@ SEARCH_FIELD = 6
SEARCH_FIELD_EXISTS = 7
SEARCH_QA = 8
SEARCH_PHRASE_WB = 9
DECK_VERSION = 71
deckVarsTable = Table(
'deckVars', metadata,
@ -127,7 +126,6 @@ class Deck(object):
factorFour = 1.3
initialFactor = 2.5
minimumAverage = 1.7
maxScheduleTime = 36500
def __init__(self, path=None):
@ -3636,10 +3634,7 @@ class DeckStorage(object):
# check if deck has been moved, and disable syncing
deck.checkSyncHash()
# determine starting factor for new cards
deck.averageFactor = (deck.s.scalar(
"select avg(factor) from cards where type = 1")
or Deck.initialFactor)
deck.averageFactor = max(deck.averageFactor, Deck.minimumAverage)
deck.averageFactor = 2.5
# rebuild queue
deck.reset()
# make sure we haven't accidentally bumped the modification time

View file

@ -2,6 +2,11 @@
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
DECK_VERSION = 72
from anki.lang import _
from anki.media import rebuildMediaDir
def upgradeSchema(s):
"Alter tables prior to ORM initialization."
ver = s.scalar("select version from decks limit 1")
@ -37,10 +42,6 @@ create index if not exists ix_facts_modified on facts
deck.s.statement("""
create index if not exists ix_cards_priority on cards
(priority)""")
# average factor
deck.s.statement("""
create index if not exists ix_cards_factor on cards
(type, factor)""")
# card spacing
deck.s.statement("""
create index if not exists ix_cards_factId on cards (factId)""")
@ -84,7 +85,6 @@ create index if not exists ix_cardTags_cardId on cardTags (cardId)""")
def upgradeDeck(deck):
"Upgrade deck to the latest version."
from anki.deck import DECK_VERSION
if deck.version < DECK_VERSION:
prog = True
deck.startProgress()
@ -229,6 +229,11 @@ this message. (ERR-0101)""") % {
deck.s.execute("analyze")
deck.version = 71
deck.s.commit()
if deck.version < 72:
# remove the expensive value cache
deck.s.statement("drop index if exists ix_cards_factor")
deck.version = 72
deck.s.commit()
# executing a pragma here is very slow on large decks, so we store
# our own record
if not deck.getInt("pageSize") == 4096: