View Single Post
Old 09-12-2021, 06:29 AM   #682
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,203
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
I made a quick test with set_metadata and it was slower than single field edit even for one book. It compounded the problem and calls Last Modified plugin multiple times per field per book.

Code:
from calibre_plugins.action_chains.actions.base import ChainAction


class Test(ChainAction):

    name = 'Test set_metadata'
    support_scopes = True

    def run(self, gui, settings, chain):
        book_ids = chain.scope().get_book_ids()
        
        db = gui.current_db
        cache = db.new_api
        
        if len(book_ids) == 0:
            return

        for book_id in book_ids:
            #mi = cache.get_proxy_metadata(book_id)
            mi = cache.get_metadata(book_id)
            mi.set('#test1', 'text')
            cache.set_metadata(book_id, mi)
Edit: It seems set_metadata() is calling set_field() for every field, even if the field value was not changed.

Last edited by capink; 09-12-2021 at 09:51 AM.
capink is offline   Reply With Quote