mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Some link map micro optimizations I missed in my previous review
This commit is contained in:
parent
6ddef11819
commit
44001e2c60
@ -2384,11 +2384,11 @@ class Cache:
|
|||||||
return cached
|
return cached
|
||||||
links = {}
|
links = {}
|
||||||
def add_links_for_field(f):
|
def add_links_for_field(f):
|
||||||
field_ids = frozenset(self.field_ids_for(f, book_id))
|
|
||||||
table = self.fields[f].table
|
table = self.fields[f].table
|
||||||
lm = table.link_map
|
lm = table.link_map
|
||||||
vm = table.id_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:
|
if d:
|
||||||
links[f] = d
|
links[f] = d
|
||||||
for field in ('authors', 'publisher', 'series', 'tags'):
|
for field in ('authors', 'publisher', 'series', 'tags'):
|
||||||
@ -2410,7 +2410,7 @@ class Cache:
|
|||||||
|
|
||||||
returns books changed by setting the link
|
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:
|
if field not in self.fields:
|
||||||
raise ValueError(f'Lookup name {field} is not a valid name')
|
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
|
# Clear the links for book cache as we don't know what will be affected
|
||||||
self.link_maps_cache = {}
|
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}
|
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)
|
result_map = table.set_links(id_to_link_map, self.backend)
|
||||||
changed_books = set()
|
changed_books = set()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user