This commit is contained in:
Kovid Goyal 2021-01-03 04:10:46 +05:30
commit 9b492bfcd6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 1 deletions

View File

@ -607,7 +607,8 @@ class Cache(object):
if not fmt:
return {}
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)
if x is not None:
return x
@ -635,6 +636,11 @@ class Cache(object):
fmts = field.table.book_col_map.get(book_id, ())
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
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. '

View File

@ -623,6 +623,9 @@ class FormatsField(ManyToManyField):
def format_fname(self, book_id, fmt):
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):
val_map = defaultdict(set)
cbm = self.table.book_col_map