From edf121f8dc272922adfcb8b27120396bc5dc3012 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 16 May 2010 01:01:38 +0900 Subject: [PATCH] add hex cache for dumb clients, make sure not to mark deck modified --- anki/deck.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/anki/deck.py b/anki/deck.py index 1046cf104..1d892fbcd 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -8,7 +8,8 @@ The Deck """ __docformat__ = 'restructuredtext' -import tempfile, time, os, random, sys, re, stat, shutil, types, traceback +import tempfile, time, os, random, sys, re, stat, shutil +import types, traceback, simplejson from anki.db import * from anki.lang import _, ngettext @@ -1315,9 +1316,20 @@ answerAlign, 0 from cardModels""")]) (hexifyID(row[0]), row[1]) for row in self.s.all(""" select id, lastFontColour from cardModels""")]) self.css = css - self.setVar("cssCache", css) + self.setVar("cssCache", css, mod=False) + self.addHexCache() return css + def addHexCache(self): + ids = self.s.column0(""" +select id from fieldModels union +select id from cardModels union +select id from models""") + cache = {} + for id in ids: + cache[id] = hexifyID(id) + self.setVar("hexCache", simplejson.dumps(cache), mod=False) + def copyModel(self, oldModel): "Add a new model to DB based on MODEL." m = Model(_("%s copy") % oldModel.name)