From 4b5a52abb4c15d35beb58ebac0dc4edc8840a005 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 17 Sep 2020 21:22:54 -0700 Subject: [PATCH] Take advantage of the tag_exports cache for get_all_tag_names. --- etiquette/photodb.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 3f0d814..f9109e7 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -258,7 +258,8 @@ class PDBCacheManagerMixin: def get_cached_tag_export(self, function, **kwargs): if isinstance(function, str): function = getattr(tag_export, function) - kwargs['tags'] = tuple(kwargs['tags']) + if 'tags' in kwargs: + kwargs['tags'] = tuple(kwargs['tags']) key = (function.__name__,) + helpers.dict_to_tuple(kwargs) try: exp = self.caches['tag_exports'][key] @@ -1062,25 +1063,31 @@ class PDBTagMixin: else: raise exceptions.TagExists(existing_tag) - def get_all_tag_names(self): - ''' - Return a list containing the names of all tags as strings. - Useful for when you don't want the overhead of actual Tag objects. - ''' + def _get_all_tag_names(self): query = 'SELECT name FROM tags' rows = self.sql_select(query) names = [row[0] for row in rows] return names - def get_all_synonyms(self): + def get_all_tag_names(self): ''' - Return a dict mapping {synonym: mastertag} as strings. + Return a list containing the names of all tags as strings. + Useful for when you don't want the overhead of actual Tag objects. ''' + return self.get_cached_tag_export(self._get_all_tag_names) + + def _get_all_synonyms(self): query = 'SELECT name, mastername FROM tag_synonyms' rows = self.sql_select(query) synonyms = {syn: tag for (syn, tag) in rows} return synonyms + def get_all_synonyms(self): + ''' + Return a dict mapping {synonym: mastertag} as strings. + ''' + return self.get_cached_tag_export(self._get_all_synonyms) + def get_root_tags(self): ''' Yield Tags that have no parent.