Replace usage of row[0] with (column,) tuple unpack.
This commit is contained in:
parent
fa57386908
commit
f8e03bed21
3 changed files with 23 additions and 25 deletions
|
@ -171,14 +171,14 @@ class GroupableMixin(metaclass=abc.ABCMeta):
|
||||||
f'SELECT memberid FROM {self.group_table} WHERE parentid == ?',
|
f'SELECT memberid FROM {self.group_table} WHERE parentid == ?',
|
||||||
[self.id]
|
[self.id]
|
||||||
)
|
)
|
||||||
child_ids = [row[0] for row in child_rows]
|
child_ids = (child_id for (child_id,) in child_rows)
|
||||||
children = set(self.group_getter_many(child_ids))
|
children = set(self.group_getter_many(child_ids))
|
||||||
return children
|
return children
|
||||||
|
|
||||||
def get_parents(self):
|
def get_parents(self):
|
||||||
query = f'SELECT parentid FROM {self.group_table} WHERE memberid == ?'
|
query = f'SELECT parentid FROM {self.group_table} WHERE memberid == ?'
|
||||||
parent_rows = self.photodb.sql_select(query, [self.id])
|
parent_rows = self.photodb.sql_select(query, [self.id])
|
||||||
parent_ids = [row[0] for row in parent_rows]
|
parent_ids = (parent_id for (parent_id,) in parent_rows)
|
||||||
parents = set(self.group_getter_many(parent_ids))
|
parents = set(self.group_getter_many(parent_ids))
|
||||||
return parents
|
return parents
|
||||||
|
|
||||||
|
@ -412,17 +412,16 @@ class Album(ObjectBase, GroupableMixin):
|
||||||
'SELECT directory FROM album_associated_directories WHERE albumid == ?',
|
'SELECT directory FROM album_associated_directories WHERE albumid == ?',
|
||||||
[self.id]
|
[self.id]
|
||||||
)
|
)
|
||||||
directories = (x[0] for x in directory_rows)
|
directories = set(pathclass.Path(directory) for (directory,) in directory_rows)
|
||||||
directories = set(pathclass.Path(x) for x in directories)
|
|
||||||
return directories
|
return directories
|
||||||
|
|
||||||
def get_photos(self):
|
def get_photos(self):
|
||||||
photos = []
|
photos = []
|
||||||
generator = self.photodb.sql_select(
|
photo_rows = self.photodb.sql_select(
|
||||||
'SELECT photoid FROM album_photo_rel WHERE albumid == ?',
|
'SELECT photoid FROM album_photo_rel WHERE albumid == ?',
|
||||||
[self.id]
|
[self.id]
|
||||||
)
|
)
|
||||||
photo_ids = [row[0] for row in generator]
|
photo_ids = (photo_id for (photo_id,) in photo_rows)
|
||||||
photos = set(self.photodb.get_photos_by_id(photo_ids))
|
photos = set(self.photodb.get_photos_by_id(photo_ids))
|
||||||
return photos
|
return photos
|
||||||
|
|
||||||
|
@ -846,11 +845,11 @@ class Photo(ObjectBase):
|
||||||
'''
|
'''
|
||||||
Return the albums of which this photo is a member.
|
Return the albums of which this photo is a member.
|
||||||
'''
|
'''
|
||||||
album_ids = self.photodb.sql_select(
|
album_rows = self.photodb.sql_select(
|
||||||
'SELECT albumid FROM album_photo_rel WHERE photoid == ?',
|
'SELECT albumid FROM album_photo_rel WHERE photoid == ?',
|
||||||
[self.id]
|
[self.id]
|
||||||
)
|
)
|
||||||
album_ids = [row[0] for row in album_ids]
|
album_ids = (album_id for (album_id,) in album_rows)
|
||||||
albums = set(self.photodb.get_albums_by_id(album_ids))
|
albums = set(self.photodb.get_albums_by_id(album_ids))
|
||||||
return albums
|
return albums
|
||||||
|
|
||||||
|
@ -858,11 +857,11 @@ class Photo(ObjectBase):
|
||||||
'''
|
'''
|
||||||
Return the tags assigned to this Photo.
|
Return the tags assigned to this Photo.
|
||||||
'''
|
'''
|
||||||
tag_ids = self.photodb.sql_select(
|
tag_rows = self.photodb.sql_select(
|
||||||
'SELECT tagid FROM photo_tag_rel WHERE photoid == ?',
|
'SELECT tagid FROM photo_tag_rel WHERE photoid == ?',
|
||||||
[self.id]
|
[self.id]
|
||||||
)
|
)
|
||||||
tag_ids = [row[0] for row in tag_ids]
|
tag_ids = (tag_id for (tag_id,) in tag_rows)
|
||||||
tags = set(self.photodb.get_tags_by_id(tag_ids))
|
tags = set(self.photodb.get_tags_by_id(tag_ids))
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
@ -1335,7 +1334,8 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
)
|
)
|
||||||
'''
|
'''
|
||||||
bindings = [self.id, mastertag.id]
|
bindings = [self.id, mastertag.id]
|
||||||
replace_photoids = [row[0] for row in self.photodb.sql_execute(query, bindings)]
|
photo_rows = self.photodb.sql_execute(query, bindings)
|
||||||
|
replace_photoids = [photo_id for (photo_id,) in photo_rows]
|
||||||
|
|
||||||
# For those photos that only had the syn, simply replace with master.
|
# For those photos that only had the syn, simply replace with master.
|
||||||
if replace_photoids:
|
if replace_photoids:
|
||||||
|
@ -1393,7 +1393,7 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
'SELECT name FROM tag_synonyms WHERE mastername == ?',
|
'SELECT name FROM tag_synonyms WHERE mastername == ?',
|
||||||
[self.name]
|
[self.name]
|
||||||
)
|
)
|
||||||
synonyms = set(row[0] for row in syn_rows)
|
synonyms = set(name for (name,) in syn_rows)
|
||||||
return synonyms
|
return synonyms
|
||||||
|
|
||||||
@decorators.required_feature('tag.edit')
|
@decorators.required_feature('tag.edit')
|
||||||
|
|
|
@ -50,10 +50,8 @@ class PDBAlbumMixin:
|
||||||
query = 'SELECT albumid FROM album_associated_directories WHERE directory == ?'
|
query = 'SELECT albumid FROM album_associated_directories WHERE directory == ?'
|
||||||
bindings = [directory.absolute_path]
|
bindings = [directory.absolute_path]
|
||||||
album_rows = self.sql_select(query, bindings)
|
album_rows = self.sql_select(query, bindings)
|
||||||
|
album_ids = (album_id for (album_id,) in album_rows)
|
||||||
for album_row in album_rows:
|
return self.get_albums_by_id(album_ids)
|
||||||
album_id = album_row[0]
|
|
||||||
yield self.get_album(album_id)
|
|
||||||
|
|
||||||
def get_root_albums(self):
|
def get_root_albums(self):
|
||||||
'''
|
'''
|
||||||
|
@ -108,8 +106,8 @@ class PDBAlbumMixin:
|
||||||
@decorators.transaction
|
@decorators.transaction
|
||||||
def purge_deleted_associated_directories(self, albums=None):
|
def purge_deleted_associated_directories(self, albums=None):
|
||||||
directories = self.sql_select('SELECT DISTINCT directory FROM album_associated_directories')
|
directories = self.sql_select('SELECT DISTINCT directory FROM album_associated_directories')
|
||||||
directories = (pathclass.Path(d[0]) for d in directories)
|
directories = (pathclass.Path(directory) for (directory,) in directories)
|
||||||
directories = [d.absolute_path for d in directories if not d.exists]
|
directories = [directory.absolute_path for directory in directories if not directory.exists]
|
||||||
if not directories:
|
if not directories:
|
||||||
return
|
return
|
||||||
self.log.debug('Purging associated directories %s', directories)
|
self.log.debug('Purging associated directories %s', directories)
|
||||||
|
@ -930,8 +928,8 @@ class PDBSQLMixin:
|
||||||
|
|
||||||
def get_sql_tables(self):
|
def get_sql_tables(self):
|
||||||
query = 'SELECT name FROM sqlite_master WHERE type = "table"'
|
query = 'SELECT name FROM sqlite_master WHERE type = "table"'
|
||||||
cur = self.sql_execute(query)
|
table_rows = self.sql_select(query)
|
||||||
tables = set(row[0] for row in cur.fetchall())
|
tables = set(name for (name,) in table_rows)
|
||||||
return tables
|
return tables
|
||||||
|
|
||||||
def release_savepoint(self, savepoint, allow_commit=False):
|
def release_savepoint(self, savepoint, allow_commit=False):
|
||||||
|
@ -1067,8 +1065,8 @@ class PDBTagMixin:
|
||||||
|
|
||||||
def _get_all_tag_names(self):
|
def _get_all_tag_names(self):
|
||||||
query = 'SELECT name FROM tags'
|
query = 'SELECT name FROM tags'
|
||||||
rows = self.sql_select(query)
|
tag_rows = self.sql_select(query)
|
||||||
names = [row[0] for row in rows]
|
names = set(name for (name,) in tag_rows)
|
||||||
return names
|
return names
|
||||||
|
|
||||||
def get_all_tag_names(self):
|
def get_all_tag_names(self):
|
||||||
|
@ -1080,8 +1078,8 @@ class PDBTagMixin:
|
||||||
|
|
||||||
def _get_all_synonyms(self):
|
def _get_all_synonyms(self):
|
||||||
query = 'SELECT name, mastername FROM tag_synonyms'
|
query = 'SELECT name, mastername FROM tag_synonyms'
|
||||||
rows = self.sql_select(query)
|
syn_rows = self.sql_select(query)
|
||||||
synonyms = {syn: tag for (syn, tag) in rows}
|
synonyms = {syn: tag for (syn, tag) in syn_rows}
|
||||||
return synonyms
|
return synonyms
|
||||||
|
|
||||||
def get_all_synonyms(self):
|
def get_all_synonyms(self):
|
||||||
|
|
|
@ -66,7 +66,7 @@ def post_tag_remove_child(tagname):
|
||||||
@site.route('/all_tags.json')
|
@site.route('/all_tags.json')
|
||||||
@caching.cached_endpoint(max_age=0)
|
@caching.cached_endpoint(max_age=0)
|
||||||
def get_all_tag_names():
|
def get_all_tag_names():
|
||||||
all_tags = common.P.get_all_tag_names()
|
all_tags = list(common.P.get_all_tag_names())
|
||||||
all_synonyms = common.P.get_all_synonyms()
|
all_synonyms = common.P.get_all_synonyms()
|
||||||
response = {'tags': all_tags, 'synonyms': all_synonyms}
|
response = {'tags': all_tags, 'synonyms': all_synonyms}
|
||||||
return jsonify.make_json_response(response)
|
return jsonify.make_json_response(response)
|
||||||
|
|
Loading…
Reference in a new issue