Remove thing_map table, just use thing_map class.table.

This commit is contained in:
voussoir 2020-04-03 13:01:28 -07:00
parent 545ea62818
commit 9c96522cfc

View file

@ -1496,8 +1496,8 @@ class PhotoDB(
''' '''
thing_map = _THING_CLASSES[thing_type] thing_map = _THING_CLASSES[thing_type]
thing_table = thing_map['table']
thing_class = thing_map['class'] thing_class = thing_map['class']
thing_table = thing_class.table
thing_cache = self.caches[thing_type] thing_cache = self.caches[thing_type]
if isinstance(db_row, dict): if isinstance(db_row, dict):
@ -1520,7 +1520,7 @@ class PhotoDB(
thing_map = _THING_CLASSES[thing_type] thing_map = _THING_CLASSES[thing_type]
thing_class = thing_map['class'] thing_class = thing_map['class']
thing_table = thing_map['table'] thing_table = thing_class.table
group_table = thing_class.group_table group_table = thing_class.group_table
query = f''' query = f'''
@ -1559,7 +1559,7 @@ class PhotoDB(
except KeyError: except KeyError:
pass pass
query = 'SELECT * FROM %s WHERE id == ?' % thing_map['table'] query = 'SELECT * FROM %s WHERE id == ?' % thing_class.table
bindings = [thing_id] bindings = [thing_id]
thing_row = self.sql_select_one(query, bindings) thing_row = self.sql_select_one(query, bindings)
if thing_row is None: if thing_row is None:
@ -1574,7 +1574,7 @@ class PhotoDB(
''' '''
thing_map = _THING_CLASSES[thing_type] thing_map = _THING_CLASSES[thing_type]
query = 'SELECT * FROM %s' % thing_map['table'] query = 'SELECT * FROM %s' % thing_map['class'].table
things = self.sql_select(query) things = self.sql_select(query)
for thing_row in things: for thing_row in things:
@ -1609,7 +1609,7 @@ class PhotoDB(
qmarks = ','.join('?' * len(id_batch)) qmarks = ','.join('?' * len(id_batch))
qmarks = '(%s)' % qmarks qmarks = '(%s)' % qmarks
query = 'SELECT * FROM %s WHERE id IN %s' % (thing_map['table'], qmarks) query = 'SELECT * FROM %s WHERE id IN %s' % (thing_class.table, qmarks)
more_things = self.sql_select(query, id_batch) more_things = self.sql_select(query, id_batch)
for thing_row in more_things: for thing_row in more_things:
# Normally we would call `get_cached_instance` instead of # Normally we would call `get_cached_instance` instead of
@ -1654,31 +1654,26 @@ _THING_CLASSES = {
{ {
'class': objects.Album, 'class': objects.Album,
'exception': exceptions.NoSuchAlbum, 'exception': exceptions.NoSuchAlbum,
'table': 'albums',
}, },
'bookmark': 'bookmark':
{ {
'class': objects.Bookmark, 'class': objects.Bookmark,
'exception': exceptions.NoSuchBookmark, 'exception': exceptions.NoSuchBookmark,
'table': 'bookmarks',
}, },
'photo': 'photo':
{ {
'class': objects.Photo, 'class': objects.Photo,
'exception': exceptions.NoSuchPhoto, 'exception': exceptions.NoSuchPhoto,
'table': 'photos',
}, },
'tag': 'tag':
{ {
'class': objects.Tag, 'class': objects.Tag,
'exception': exceptions.NoSuchTag, 'exception': exceptions.NoSuchTag,
'table': 'tags',
}, },
'user': 'user':
{ {
'class': objects.User, 'class': objects.User,
'exception': exceptions.NoSuchUser, 'exception': exceptions.NoSuchUser,
'table': 'users',
} }
} }