Some link map micro optimizations I missed in my previous review

This commit is contained in:
Kovid Goyal 2023-03-30 13:25:54 +05:30
parent 6ddef11819
commit 44001e2c60
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -2384,11 +2384,11 @@ class Cache:
return cached
links = {}
def add_links_for_field(f):
field_ids = frozenset(self.field_ids_for(f, book_id))
table = self.fields[f].table
lm = table.link_map
vm = table.id_map
d = {vm.get(fid):v for fid,v in lm.items() if v and fid in field_ids}
d = {vm.get(fid):v for fid, v in lm.items() if v}
d.pop(None, None)
if d:
links[f] = d
for field in ('authors', 'publisher', 'series', 'tags'):
@ -2410,7 +2410,7 @@ class Cache:
returns books changed by setting the link
NB: this method doesn't change values not in the value_to_link_map
Note: this method doesn't change values not in the value_to_link_map
'''
if field not in self.fields:
raise ValueError(f'Lookup name {field} is not a valid name')
@ -2420,7 +2420,7 @@ class Cache:
# Clear the links for book cache as we don't know what will be affected
self.link_maps_cache = {}
fids = {k: self.get_item_id(field, k) for k in value_to_link_map.keys()}
fids = self._get_item_ids(field, value_to_link_map)
id_to_link_map = {fid:value_to_link_map[k] for k, fid in fids.items() if fid is not None}
result_map = table.set_links(id_to_link_map, self.backend)
changed_books = set()