From 44001e2c607884d58d111d07996c2ef12fc8f8bf Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 30 Mar 2023 13:25:54 +0530 Subject: [PATCH] Some link map micro optimizations I missed in my previous review --- src/calibre/db/cache.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 0a3f6b4d69..aac848f7d5 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -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()