From abe82dde9ee0dde780f7bb9c70058ffae686a03e Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 31 Mar 2018 14:01:03 -0700 Subject: [PATCH] Let get_tag_by_name use cache after finding the ID. --- etiquette/photodb.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 543e4cc..22360dd 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -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.