Add a method to db.cache to return the size of a format stored in the database table 'data'. With this method one can compare the real size to the stored size.

This commit is contained in:
Charles Haley 2021-01-02 15:07:21 +00:00
parent 533aa3206e
commit 5a3d65a132
2 changed files with 10 additions and 1 deletions

View File

@ -607,7 +607,8 @@ class Cache(object):
if not fmt: if not fmt:
return {} return {}
fmt = fmt.upper() fmt = fmt.upper()
if allow_cache: # allow_cache and update_db are mutually exclusive. Give priority to update_db
if allow_cache and not update_db:
x = self.format_metadata_cache[book_id].get(fmt, None) x = self.format_metadata_cache[book_id].get(fmt, None)
if x is not None: if x is not None:
return x return x
@ -635,6 +636,11 @@ class Cache(object):
fmts = field.table.book_col_map.get(book_id, ()) fmts = field.table.book_col_map.get(book_id, ())
return {fmt:field.format_fname(book_id, fmt) for fmt in fmts} return {fmt:field.format_fname(book_id, fmt) for fmt in fmts}
@read_api
def format_db_size(self, book_id, fmt):
field = self.fields['formats']
return field.format_size(book_id, fmt)
@read_api @read_api
def pref(self, name, default=None, namespace=None): def pref(self, name, default=None, namespace=None):
' Return the value for the specified preference or the value specified as ``default`` if the preference is not set. ' ' Return the value for the specified preference or the value specified as ``default`` if the preference is not set. '

View File

@ -623,6 +623,9 @@ class FormatsField(ManyToManyField):
def format_fname(self, book_id, fmt): def format_fname(self, book_id, fmt):
return self.table.fname_map[book_id][fmt.upper()] return self.table.fname_map[book_id][fmt.upper()]
def format_size(self, book_id, fmt):
return self.table.size_map.get(book_id, {}).get(fmt.upper(), None)
def iter_searchable_values(self, get_metadata, candidates, default_value=None): def iter_searchable_values(self, get_metadata, candidates, default_value=None):
val_map = defaultdict(set) val_map = defaultdict(set)
cbm = self.table.book_col_map cbm = self.table.book_col_map