Rename cached_frozen_children -> cached_tag_flat_dict.

This commit is contained in:
voussoir 2020-09-12 00:56:32 -07:00
parent b59c2700db
commit 21921dc8fc
2 changed files with 16 additions and 18 deletions

View file

@ -112,7 +112,7 @@ class GroupableMixin:
} }
self.photodb.sql_insert(table=self.group_table, data=data) self.photodb.sql_insert(table=self.group_table, data=data)
self.photodb._cached_frozen_children = None self.photodb._cached_tag_flat_dict = None
def add_children(self, members): def add_children(self, members):
for member in members: for member in members:
@ -137,7 +137,7 @@ class GroupableMixin:
If True, all children will be deleted. If True, all children will be deleted.
Otherwise they'll just be raised up one level. Otherwise they'll just be raised up one level.
''' '''
self.photodb._cached_frozen_children = None self.photodb._cached_tag_flat_dict = None
if delete_children: if delete_children:
for child in self.get_children(): for child in self.get_children():
child.delete(delete_children=True) child.delete(delete_children=True)
@ -197,7 +197,7 @@ class GroupableMixin:
'memberid': member.id, 'memberid': member.id,
} }
self.photodb.sql_delete(table=self.group_table, pairs=pairs) self.photodb.sql_delete(table=self.group_table, pairs=pairs)
self.photodb._cached_frozen_children = None self.photodb._cached_tag_flat_dict = None
def walk_children(self): def walk_children(self):
''' '''
@ -1219,7 +1219,7 @@ class Tag(ObjectBase, GroupableMixin):
self.photodb.log.debug('New synonym %s of %s', synname, self.name) self.photodb.log.debug('New synonym %s of %s', synname, self.name)
self.photodb._cached_frozen_children = None self.photodb._cached_tag_flat_dict = None
data = { data = {
'name': synname, 'name': synname,
@ -1242,7 +1242,7 @@ class Tag(ObjectBase, GroupableMixin):
''' '''
mastertag = self.photodb.get_tag(name=mastertag) mastertag = self.photodb.get_tag(name=mastertag)
self.photodb._cached_frozen_children = None self.photodb._cached_tag_flat_dict = None
# Migrate the old tag's synonyms to the new one # Migrate the old tag's synonyms to the new one
# UPDATE is safe for this operation because there is no chance of duplicates. # UPDATE is safe for this operation because there is no chance of duplicates.
@ -1295,7 +1295,7 @@ class Tag(ObjectBase, GroupableMixin):
@decorators.transaction @decorators.transaction
def delete(self, *, delete_children=False): def delete(self, *, delete_children=False):
self.photodb.log.debug('Deleting %s', self) self.photodb.log.debug('Deleting %s', self)
self.photodb._cached_frozen_children = None self.photodb._cached_tag_flat_dict = None
GroupableMixin.delete(self, delete_children=delete_children) GroupableMixin.delete(self, delete_children=delete_children)
self.photodb.sql_delete(table='photo_tag_rel', pairs={'tagid': self.id}) self.photodb.sql_delete(table='photo_tag_rel', pairs={'tagid': self.id})
self.photodb.sql_delete(table='tag_synonyms', pairs={'mastername': self.name}) self.photodb.sql_delete(table='tag_synonyms', pairs={'mastername': self.name})
@ -1354,7 +1354,7 @@ class Tag(ObjectBase, GroupableMixin):
if syn_exists is None: if syn_exists is None:
raise exceptions.NoSuchSynonym(synname) raise exceptions.NoSuchSynonym(synname)
self.photodb._cached_frozen_children = None self.photodb._cached_tag_flat_dict = None
self.photodb.sql_delete(table='tag_synonyms', pairs={'name': synname}) self.photodb.sql_delete(table='tag_synonyms', pairs={'name': synname})
@decorators.required_feature('tag.edit') @decorators.required_feature('tag.edit')
@ -1375,7 +1375,7 @@ class Tag(ObjectBase, GroupableMixin):
else: else:
raise exceptions.TagExists(new_name) raise exceptions.TagExists(new_name)
self.photodb._cached_frozen_children = None self.photodb._cached_tag_flat_dict = None
data = { data = {
'id': self.id, 'id': self.id,

View file

@ -657,7 +657,6 @@ class PDBPhotoMixin:
(tag_musts, tag_mays, tag_forbids, tag_expression) = tags_fixed (tag_musts, tag_mays, tag_forbids, tag_expression) = tags_fixed
if tag_expression: if tag_expression:
frozen_children = self.get_cached_frozen_children()
tag_expression_tree = searchhelpers.tag_expression_tree_builder( tag_expression_tree = searchhelpers.tag_expression_tree_builder(
tag_expression=tag_expression, tag_expression=tag_expression,
photodb=self, photodb=self,
@ -668,6 +667,7 @@ class PDBPhotoMixin:
tag_expression = None tag_expression = None
else: else:
giveback_tag_expression = str(tag_expression_tree) giveback_tag_expression = str(tag_expression_tree)
frozen_children = self.get_cached_tag_flat_dict()
tag_match_function = searchhelpers.tag_expression_matcher_builder(frozen_children) tag_match_function = searchhelpers.tag_expression_matcher_builder(frozen_children)
else: else:
giveback_tag_expression = None giveback_tag_expression = None
@ -1121,7 +1121,7 @@ class PDBTagMixin:
author_id = self.get_user_id_or_none(author) author_id = self.get_user_id_or_none(author)
self._uncache() self._cached_tag_flat_dict = None
data = { data = {
'id': tag_id, 'id': tag_id,
@ -1636,7 +1636,7 @@ class PhotoDB(
self.log.setLevel(self.config['log_level']) self.log.setLevel(self.config['log_level'])
# OTHER # OTHER
self._cached_frozen_children = None self._cached_tag_flat_dict = None
self.caches = { self.caches = {
'album': cacheclass.Cache(maxlen=self.config['cache_size']['album']), 'album': cacheclass.Cache(maxlen=self.config['cache_size']['album']),
@ -1678,9 +1678,6 @@ class PhotoDB(
else: else:
return f'PhotoDB(data_directory={self.data_directory})' return f'PhotoDB(data_directory={self.data_directory})'
def _uncache(self):
self._cached_frozen_children = None
def close(self): def close(self):
# Wrapped in hasattr because if the object fails __init__, Python will # Wrapped in hasattr because if the object fails __init__, Python will
# still call __del__ and thus close(), even though the attributes # still call __del__ and thus close(), even though the attributes
@ -1724,10 +1721,11 @@ class PhotoDB(
self.sql_update(table='id_numbers', pairs=pairs, where_key='tab') self.sql_update(table='id_numbers', pairs=pairs, where_key='tab')
return new_id return new_id
def get_cached_frozen_children(self): def get_cached_tag_flat_dict(self):
if self._cached_frozen_children is None: if self._cached_tag_flat_dict is None:
self._cached_frozen_children = tag_export.flat_dict(self.get_tags()) self._cached_tag_flat_dict = tag_export.flat_dict(self.get_root_tags())
return self._cached_frozen_children print(len(self._cached_tag_flat_dict))
return self._cached_tag_flat_dict
def load_config(self): def load_config(self):
(config, needs_rewrite) = configlayers.load_file( (config, needs_rewrite) = configlayers.load_file(