mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02: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."
|
"Add stripped HTML cache for searching."
|
||||||
r = []
|
r = []
|
||||||
from anki.utils import stripHTMLMedia
|
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()]
|
for (id, map) in facts.items()]
|
||||||
self.db.executemany(
|
self.db.executemany(
|
||||||
"update facts set cache=? where id=?", r)
|
"update facts set cache=? where id=?", r)
|
||||||
|
|
|
@ -152,8 +152,6 @@ insert or replace into fields values (?, ?, ?, ?, ?, ?)""",
|
||||||
# Template object
|
# Template object
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
# FIXME: change typeAnswer to field id
|
|
||||||
|
|
||||||
defaultTemplateConf = {
|
defaultTemplateConf = {
|
||||||
'hideQ': False,
|
'hideQ': False,
|
||||||
'align': 0,
|
'align': 0,
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
CURRENT_VERSION = 100
|
CURRENT_VERSION = 100
|
||||||
|
|
||||||
import os, time, simplejson
|
import os, time, simplejson, re
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from anki.utils import intTime
|
from anki.utils import intTime
|
||||||
from anki.db import DB
|
from anki.db import DB
|
||||||
|
@ -45,7 +45,7 @@ def _createDB(db):
|
||||||
db.execute("analyze")
|
db.execute("analyze")
|
||||||
return CURRENT_VERSION
|
return CURRENT_VERSION
|
||||||
|
|
||||||
def _addSchema(db, addObjs=True):
|
def _addSchema(db, setDeckConf=True):
|
||||||
db.executescript("""
|
db.executescript("""
|
||||||
create table if not exists deck (
|
create table if not exists deck (
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
|
@ -173,21 +173,20 @@ create table if not exists tags (
|
||||||
insert or ignore into deck
|
insert or ignore into deck
|
||||||
values(1,%(t)s,%(t)s,%(t)s,%(v)s,'',0,-2,'', '', '');
|
values(1,%(t)s,%(t)s,%(t)s,%(v)s,'',0,-2,'', '', '');
|
||||||
""" % ({'t': intTime(), 'v':CURRENT_VERSION}))
|
""" % ({'t': intTime(), 'v':CURRENT_VERSION}))
|
||||||
# if not upgrading
|
import anki.deck
|
||||||
if addObjs:
|
import anki.groups
|
||||||
import anki.deck
|
db.execute(
|
||||||
import anki.groups
|
"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 = ?",
|
db.execute("update deck set qconf = ?, conf = ?, data = ?",
|
||||||
simplejson.dumps(anki.deck.defaultQconf),
|
simplejson.dumps(anki.deck.defaultQconf),
|
||||||
simplejson.dumps(anki.deck.defaultConf),
|
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):
|
def _updateIndices(db):
|
||||||
"Add indices to the DB."
|
"Add indices to the DB."
|
||||||
|
@ -421,8 +420,12 @@ def _postSchemaUpgrade(deck):
|
||||||
"revCardsDue", "revCardsRandom", "acqCardsRandom",
|
"revCardsDue", "revCardsRandom", "acqCardsRandom",
|
||||||
"acqCardsOld", "acqCardsNew"):
|
"acqCardsOld", "acqCardsNew"):
|
||||||
deck.db.execute("drop view if exists %s" % v)
|
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 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()
|
m.updateCache()
|
||||||
# remove stats, as it's all in the revlog now
|
# remove stats, as it's all in the revlog now
|
||||||
deck.db.execute("drop table if exists stats")
|
deck.db.execute("drop table if exists stats")
|
||||||
|
|
Loading…
Reference in a new issue