Use a getter for link_maps in ProxyMetadata

Also allow is_null() to work with it.
This commit is contained in:
Kovid Goyal 2023-03-30 08:56:19 +05:30
parent aabd29c571
commit 6ddef11819
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 12 additions and 5 deletions

View File

@ -391,7 +391,7 @@ class Cache:
for key in composites:
mi.set(key, val=self._composite_for(key, book_id, mi))
mi.link_maps = self.get_all_link_maps_for_book(book_id)
mi.link_maps = self._get_all_link_maps_for_book(book_id)
user_cat_vals = {}
if get_user_categories:

View File

@ -147,6 +147,15 @@ def adata_getter(field):
return func
def link_maps_getter(dbref, book_id, cache):
try:
ans = cache['link_maps']
except KeyError:
db = dbref()
ans = cache['link_maps'] = db.get_all_link_maps_for_book(book_id)
return ans
def dt_getter(field):
def func(dbref, book_id, cache):
try:
@ -300,6 +309,7 @@ getters = {
'application_id':lambda x, book_id, y: book_id,
'id':lambda x, book_id, y: book_id,
'virtual_libraries':virtual_libraries_getter,
'link_maps': link_maps_getter,
}
for field in ('comments', 'publisher', 'identifiers', 'series', 'rating'):
@ -351,10 +361,6 @@ class ProxyMetadata(Metadata):
return custom_getter(field, ga(self, '_db'), ga(self, '_book_id'), ga(self, '_cache'))
return composite_getter(self, field, ga(self, '_db'), ga(self, '_book_id'), ga(self, '_cache'), ga(self, 'formatter'), ga(self, 'template_cache'))
if field == 'link_maps':
db = ga(self, '_db')()
return db.get_all_link_maps_for_book(ga(self, '_book_id'))
try:
return ga(self, '_cache')[field]
except KeyError:

View File

@ -46,6 +46,7 @@ NULL_VALUES = {
'title' : _('Unknown'),
'user_categories' : {},
'author_link_map' : {},
'link_maps' : {},
'language' : 'und'
}