From 541dd3e38e8bcd08b5d76ffb8411f7627aa80b6e Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 18 Apr 2009 02:39:18 +0900 Subject: [PATCH] improve speed of tagIds() --- anki/tags.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/anki/tags.py b/anki/tags.py index a8814bf3c..dd72c7d91 100644 --- a/anki/tags.py +++ b/anki/tags.py @@ -47,7 +47,14 @@ insert or ignore into tags return s.scalar("select id from tags where tag = :tag", tag=tag) def tagIds(s, tags): + "Return an ID for all tags, creating if necessary." ids = {} + s.statements("insert or ignore into tags (tag) values (:tag)", + [{'tag': t} for t in tags]) + tagsD = dict(s.all(""" +select lower(tag), id from tags +where tag in (%s)""" % ",".join([ + "'%s'" % t.replace("'", "''") for t in tags]))) for tag in tags: - ids[tag.lower()] = tagId(s, tag) + ids[tag.lower()] = tagsD[tag.lower()] return ids