mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
improve speed of tagIds()
This commit is contained in:
parent
19e597cbc9
commit
541dd3e38e
1 changed files with 8 additions and 1 deletions
|
@ -47,7 +47,14 @@ insert or ignore into tags
|
||||||
return s.scalar("select id from tags where tag = :tag", tag=tag)
|
return s.scalar("select id from tags where tag = :tag", tag=tag)
|
||||||
|
|
||||||
def tagIds(s, tags):
|
def tagIds(s, tags):
|
||||||
|
"Return an ID for all tags, creating if necessary."
|
||||||
ids = {}
|
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:
|
for tag in tags:
|
||||||
ids[tag.lower()] = tagId(s, tag)
|
ids[tag.lower()] = tagsD[tag.lower()]
|
||||||
return ids
|
return ids
|
||||||
|
|
Loading…
Reference in a new issue