Let get_tag_by_name use cache after finding the ID.

This commit is contained in:
voussoir 2018-03-31 14:01:03 -07:00
parent ac41598bb0
commit abe82dde9e

View file

@ -811,11 +811,12 @@ class PDBTagMixin:
except (exceptions.TagTooShort, exceptions.TagTooLong):
raise exceptions.NoSuchTag(tagname)
tag_row = None
while True:
# Return if it's a toplevel...
tag_row = self.sql_select_one('SELECT * FROM tags WHERE name == ?', [tagname])
if tag_row is not None:
return objects.Tag(self, tag_row)
break
# ...or resolve the synonym and try again.
query = 'SELECT mastername FROM tag_synonyms WHERE name == ?'
@ -826,6 +827,13 @@ class PDBTagMixin:
raise exceptions.NoSuchTag(tagname)
tagname = name_row[0]
tag_id = tag_row[constants.SQL_INDEX['tags']['id']]
tag = self._tag_cache.get(tag_id, fallback=None)
if tag is None:
tag = objects.Tag(self, tag_row)
self._tag_cache[tag_id] = tag
return tag
def get_tags(self):
'''
Yield all Tags in the database.