Quote:
Originally Posted by JimmXinu
I don't see any obvious inefficiencies, unless db.set_custom() has started started doing commits too.
|
The legacy method db.set_custom() ignores the 'commit' parameter. Every call ends up calling db.new_api.set_field(), which does commit the operation. This isn't new -- I think it was changed in calibre V4.
To avoid the commits you should use the book_id_to_val_map parameter of set_field() (in calibre.db.cache). Using your description of the processing you would:
- map = dict()
- First remove the series name from all books that have it. Search for all books with that series. For each book found, do
- Set the series for all the books in the list along with the series index. For each book in the list do
Code:
map[book_id] = '{} [{}]'.format(series_lookup_name, series_index)
Note that series_index can't be empty. If it is then use
Code:
map[book_id] = series_lookup_name
- Call db.new_api.set_field(series_name, map). This will do all the operations in one transaction.
(NB: there might be syntax errors in the code. I didn't try to run it.)
The operation order is important. The second operation will add back any series that was deleted in the first operation.