mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add UUID cache to new db backend
This commit is contained in:
parent
dd3301c18f
commit
b24493d7e8
@ -29,7 +29,7 @@ from calibre.utils.magick.draw import save_cover_data_to
|
|||||||
from calibre.utils.recycle_bin import delete_tree
|
from calibre.utils.recycle_bin import delete_tree
|
||||||
from calibre.db.tables import (OneToOneTable, ManyToOneTable, ManyToManyTable,
|
from calibre.db.tables import (OneToOneTable, ManyToOneTable, ManyToManyTable,
|
||||||
SizeTable, FormatsTable, AuthorsTable, IdentifiersTable, PathTable,
|
SizeTable, FormatsTable, AuthorsTable, IdentifiersTable, PathTable,
|
||||||
CompositeTable, LanguagesTable)
|
CompositeTable, LanguagesTable, UUIDTable)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@ -701,7 +701,7 @@ class DB(object):
|
|||||||
if col == 'cover' else col)
|
if col == 'cover' else col)
|
||||||
if not metadata['column']:
|
if not metadata['column']:
|
||||||
metadata['column'] = col
|
metadata['column'] = col
|
||||||
tables[col] = (PathTable if col == 'path' else OneToOneTable)(col, metadata)
|
tables[col] = (PathTable if col == 'path' else UUIDTable if col == 'uuid' else OneToOneTable)(col, metadata)
|
||||||
|
|
||||||
for col in ('series', 'publisher', 'rating'):
|
for col in ('series', 'publisher', 'rating'):
|
||||||
tables[col] = ManyToOneTable(col, self.field_metadata[col].copy())
|
tables[col] = ManyToOneTable(col, self.field_metadata[col].copy())
|
||||||
|
@ -98,6 +98,17 @@ class SizeTable(OneToOneTable):
|
|||||||
'WHERE data.book=books.id) FROM books'):
|
'WHERE data.book=books.id) FROM books'):
|
||||||
self.book_col_map[row[0]] = self.unserialize(row[1])
|
self.book_col_map[row[0]] = self.unserialize(row[1])
|
||||||
|
|
||||||
|
class UUIDTable(OneToOneTable):
|
||||||
|
|
||||||
|
def read(self, db):
|
||||||
|
OneToOneTable.read(self, db)
|
||||||
|
self.uuid_to_id_map = {v:k for k, v in self.book_col_map.iteritems()}
|
||||||
|
|
||||||
|
def update_uuid_cache(self, book_id_val_map):
|
||||||
|
for book_id, uuid in book_id_val_map.iteritems():
|
||||||
|
self.uuid_to_id_map.pop(self.book_col_map[book_id], None) # discard old uuid
|
||||||
|
self.uuid_to_id_map[uuid] = book_id
|
||||||
|
|
||||||
class CompositeTable(OneToOneTable):
|
class CompositeTable(OneToOneTable):
|
||||||
|
|
||||||
def read(self, db):
|
def read(self, db):
|
||||||
|
@ -174,12 +174,19 @@ def one_one_in_books(book_id_val_map, db, field, *args):
|
|||||||
db.conn.executemany(
|
db.conn.executemany(
|
||||||
'UPDATE books SET %s=? WHERE id=?'%field.metadata['column'], sequence)
|
'UPDATE books SET %s=? WHERE id=?'%field.metadata['column'], sequence)
|
||||||
field.table.book_col_map.update(book_id_val_map)
|
field.table.book_col_map.update(book_id_val_map)
|
||||||
if field.name == 'title':
|
|
||||||
# Set the title sort field
|
|
||||||
field.title_sort_field.writer.set_books(
|
|
||||||
{k:title_sort(v) for k, v in book_id_val_map.iteritems()}, db)
|
|
||||||
return set(book_id_val_map)
|
return set(book_id_val_map)
|
||||||
|
|
||||||
|
def set_uuid(book_id_val_map, db, field, *args):
|
||||||
|
field.table.update_uuid_cache(book_id_val_map)
|
||||||
|
return one_one_in_books(book_id_val_map, db, field, *args)
|
||||||
|
|
||||||
|
def set_title(book_id_val_map, db, field, *args):
|
||||||
|
ans = one_one_in_books(book_id_val_map, db, field, *args)
|
||||||
|
# Set the title sort field
|
||||||
|
field.title_sort_field.writer.set_books(
|
||||||
|
{k:title_sort(v) for k, v in book_id_val_map.iteritems()}, db)
|
||||||
|
return ans
|
||||||
|
|
||||||
def one_one_in_other(book_id_val_map, db, field, *args):
|
def one_one_in_other(book_id_val_map, db, field, *args):
|
||||||
'Set a one-one field in the non-books table, like comments'
|
'Set a one-one field in the non-books table, like comments'
|
||||||
deleted = tuple((k,) for k, v in book_id_val_map.iteritems() if v is None)
|
deleted = tuple((k,) for k, v in book_id_val_map.iteritems() if v is None)
|
||||||
@ -460,6 +467,10 @@ class Writer(object):
|
|||||||
self.set_books_func = custom_series_index
|
self.set_books_func = custom_series_index
|
||||||
elif self.name == 'identifiers':
|
elif self.name == 'identifiers':
|
||||||
self.set_books_func = identifiers
|
self.set_books_func = identifiers
|
||||||
|
elif self.name == 'uuid':
|
||||||
|
self.set_books_func = set_uuid
|
||||||
|
elif self.name == 'title':
|
||||||
|
self.set_books_func = set_title
|
||||||
elif field.is_many_many:
|
elif field.is_many_many:
|
||||||
self.set_books_func = many_many
|
self.set_books_func = many_many
|
||||||
elif field.is_many:
|
elif field.is_many:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user