mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
fix a few upgrade/cache issues
- make sure we're actually stripping text in the field cache - make sure a default group is added on upgrade - make sure old style field references are upgrade
This commit is contained in:
parent
88469a4876
commit
e21c944aeb
3 changed files with 19 additions and 17 deletions
|
@ -980,7 +980,8 @@ order by fdata.fid""" % ids2str(ids)), itemgetter(0)):
|
|||
"Add stripped HTML cache for searching."
|
||||
r = []
|
||||
from anki.utils import stripHTMLMedia
|
||||
[r.append((" ".join([x[1] for x in map.values()]), id))
|
||||
[r.append((stripHTMLMedia(
|
||||
" ".join([x[1] for x in map.values()])), id))
|
||||
for (id, map) in facts.items()]
|
||||
self.db.executemany(
|
||||
"update facts set cache=? where id=?", r)
|
||||
|
|
|
@ -152,8 +152,6 @@ insert or replace into fields values (?, ?, ?, ?, ?, ?)""",
|
|||
# Template object
|
||||
##########################################################################
|
||||
|
||||
# FIXME: change typeAnswer to field id
|
||||
|
||||
defaultTemplateConf = {
|
||||
'hideQ': False,
|
||||
'align': 0,
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
CURRENT_VERSION = 100
|
||||
|
||||
import os, time, simplejson
|
||||
import os, time, simplejson, re
|
||||
from anki.lang import _
|
||||
from anki.utils import intTime
|
||||
from anki.db import DB
|
||||
|
@ -45,7 +45,7 @@ def _createDB(db):
|
|||
db.execute("analyze")
|
||||
return CURRENT_VERSION
|
||||
|
||||
def _addSchema(db, addObjs=True):
|
||||
def _addSchema(db, setDeckConf=True):
|
||||
db.executescript("""
|
||||
create table if not exists deck (
|
||||
id integer primary key,
|
||||
|
@ -173,21 +173,20 @@ create table if not exists tags (
|
|||
insert or ignore into deck
|
||||
values(1,%(t)s,%(t)s,%(t)s,%(v)s,'',0,-2,'', '', '');
|
||||
""" % ({'t': intTime(), 'v':CURRENT_VERSION}))
|
||||
# if not upgrading
|
||||
if addObjs:
|
||||
import anki.deck
|
||||
import anki.groups
|
||||
import anki.deck
|
||||
import anki.groups
|
||||
db.execute(
|
||||
"insert or ignore into gconf values (1, ?, ?, ?)""",
|
||||
intTime(), _("Default Config"),
|
||||
simplejson.dumps(anki.groups.defaultConf))
|
||||
db.execute(
|
||||
"insert or ignore into groups values (1, ?, ?, 1)",
|
||||
intTime(), _("Default Group"))
|
||||
if setDeckConf:
|
||||
db.execute("update deck set qconf = ?, conf = ?, data = ?",
|
||||
simplejson.dumps(anki.deck.defaultQconf),
|
||||
simplejson.dumps(anki.deck.defaultConf),
|
||||
"{}")
|
||||
db.execute(
|
||||
"insert or ignore into gconf values (1, ?, ?, ?)""",
|
||||
intTime(), _("Default Config"),
|
||||
simplejson.dumps(anki.groups.defaultConf))
|
||||
db.execute(
|
||||
"insert or ignore into groups values (1, ?, ?, 1)",
|
||||
intTime(), _("Default Group"))
|
||||
|
||||
def _updateIndices(db):
|
||||
"Add indices to the DB."
|
||||
|
@ -421,8 +420,12 @@ def _postSchemaUpgrade(deck):
|
|||
"revCardsDue", "revCardsRandom", "acqCardsRandom",
|
||||
"acqCardsOld", "acqCardsNew"):
|
||||
deck.db.execute("drop view if exists %s" % v)
|
||||
# update caches
|
||||
# ensure all templates use the new style field format, and update cach
|
||||
for m in deck.allModels():
|
||||
for t in m.templates:
|
||||
t.qfmt = re.sub("%\((.+?)\)s", "{{\\1}}", t.qfmt)
|
||||
t.afmt = re.sub("%\((.+?)\)s", "{{\\1}}", t.afmt)
|
||||
m.flush()
|
||||
m.updateCache()
|
||||
# remove stats, as it's all in the revlog now
|
||||
deck.db.execute("drop table if exists stats")
|
||||
|
|
Loading…
Reference in a new issue