Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 09-11-2021, 08:03 AM   #676
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,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
The single field edit actually calls set_field() once per field for all book_ids in the scope (single call per field). But if you use multiple single field actions for different fields, it will call set_field() for each field. AFAIK you cannot call set_field() for multiple fields.

Edit: Also if for some reason a user is changing the same field more than once in the same chain (I don't know why anyone would do this), he can use the set_book_vars(), and commit only the final change at the very end using single field edit.

Last edited by capink; 09-11-2021 at 08:17 AM.
capink is offline   Reply With Quote
Old 09-11-2021, 09:29 AM   #677
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,453
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
AFAIK you cannot call set_field() for multiple fields.
You can set multiple fields for a single book using set_metadata().

I don't know at what point, if any, iterating over books calling set_metadata() would be faster than iterating over fields calling set_field().
chaley is offline   Reply With Quote
Old 09-11-2021, 09:57 AM   #678
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,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
I would guess iterating over fields using set_field() is faster than iterating over books with set_metadata() in most situations. noteworthy is that Calibre's mass metadata edit calls set_field() regardless of the number of books it operates on. Will do some tests and see how it goes.
capink is offline   Reply With Quote
Old 09-11-2021, 10:17 AM   #679
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,453
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
noteworthy is that Calibre's mass metadata edit calls set_field() regardless of the number of books it operates on.
But with auto-commit turned off so the transactions are grouped into one commit.
Quote:
Will do some tests and see how it goes.
Thanks.
chaley is offline   Reply With Quote
Old 09-11-2021, 02:26 PM   #680
queensacrifice
Junior Member
queensacrifice began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Sep 2020
Device: Kindle Paperwhite
I think the template scopes dialog might not be registering as exited properly for me because after editing it, the default template dialog values rather than book values are retrieved for from_selection() until I open and exit a different template dialog, such as formulas.
queensacrifice is offline   Reply With Quote
Old 09-11-2021, 06:48 PM   #681
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,043
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
If it'll help for testing purposes, here's my most complicated cleanup chain and an empty test DB with all the needed columns. (If you need books, I can add a few.) Note that you might need to remove the first "clean comments" as it's plugin.
Attached Files
File Type: zip CleanupFanfics.zip (3.0 KB, 314 views)
File Type: zip metadata.zip (51.4 KB, 312 views)

Last edited by ownedbycats; 09-11-2021 at 06:51 PM.
ownedbycats is offline   Reply With Quote
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,199
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
Old 09-12-2021, 09:53 AM   #683
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,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by queensacrifice View Post
I think the template scopes dialog might not be registering as exited properly for me because after editing it, the default template dialog values rather than book values are retrieved for from_selection() until I open and exit a different template dialog, such as formulas.
I don't understand the issue. Can you please elaborate more clearly by giving steps to replicate the issue you are trying to describe?
capink is offline   Reply With Quote
Old 09-12-2021, 12:18 PM   #684
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,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by capink View Post
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.


Edit: It seems set_metadata() is calling set_field() for every field, even if the field value was not changed.
set_metadata() completely wrecks havoc with Last Modified plugin because it overwrites all the fields, even if the value has not changed, and emits db event, falsely notifying Last Modified plugin about modification in those fields.

Problem is, set_metadata() is used by a number of plugins (e.g. Import List). The solution for this mess is to retire the Last Modified plugin, because in the current state, it cannot do its advertised job.

If anyone knows what is required to retire a plugin, please tell me. Is it enough to simply remove from the Index of plugins thread? Or is there something else I have to do?
capink is offline   Reply With Quote
Old 09-12-2021, 02:00 PM   #685
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,453
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
@capink: the right fix is to change calibre base so that it doesn't set values equal to themselves. This already happens for some fields like tags.

I have been looking at the field writers and have been able to make this work with all fields except custom series indexes. Problem: I don't know what I might be breaking, so Kovid needs to be involved. I will continue to work on this but I don't know what my constraints are.

I suggest you open a bug report suggesting that
Code:
set_metadata(id_, get_metadata(_id))
shouldn't signal any dirty books and see what he says.
chaley is offline   Reply With Quote
Old 09-12-2021, 02:53 PM   #686
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,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
@chaley: Thanks for your response and help. I will have a look at it, and open the bug report, probably tomorrow, even though I've already bugged Kovid enough about this.
capink is offline   Reply With Quote
Old 09-12-2021, 03:26 PM   #687
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,453
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
@chaley: Thanks for your response and help. I will have a look at it, and open the bug report, probably tomorrow, even though I've already bugged Kovid enough about this.
At least this report is as much about performance as avoiding the changed events. In some cases updating a field without changing the value actually updates the database, which I imagine should be avoided.

Tomorrow I hope to be able to push changes for review. I don't expect the changes to be complete or even correct, but they should provide something to work with.

With the changes I have made you get changed events for the set_field() operations, but with an empty book set. I don't know if it is worth trying to filter those out at the source. I have a test function that runs over a given library calling
Code:
set_metadata(id_, get_metadata(id_))
on each book. The test works if all changed events have an empty book set.
chaley is offline   Reply With Quote
Old 09-13-2021, 03:57 AM   #688
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,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
I suggest you open a bug report suggesting that
Code:
set_metadata(id_, get_metadata(_id))
shouldn't signal any dirty books and see what he says.
I tried this and it does not make a difference, the set_metadata() still calls set_field() for every field, which in turn will dispatch a db event. I think I may have misunderstood you here.

Quote:
Originally Posted by chaley View Post
With the changes I have made you get changed events for the set_field() operations, but with an empty book set. I don't know if it is worth trying to filter those out at the
I don't think it is worth filtering out. At least in my case, they will be discarded.
capink is offline   Reply With Quote
Old 09-13-2021, 04:56 AM   #689
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,453
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
Quote:
Originally Posted by chaley View Post
I suggest you open a bug report suggesting that
Code:
set_metadata(id_, get_metadata(_id))
shouldn't signal any dirty books and see what he says.
I tried this and it does not make a difference, the set_metadata() still calls set_field() for every field, which in turn will dispatch a db event. I think I may have misunderstood you here.
This tests whether setting a book's metadata to itself generates any events with a non-empty set of books. In particular it tests whether set_field() thinks the book was dirtied when in theory it shouldn't have been.

Quote:
Originally Posted by capink View Post
Quote:
Originally Posted by chaley View Post
With the changes I have made you get changed events for the set_field() operations, but with an empty book set. I don't know if it is worth trying to filter those out at the
I don't think it is worth filtering out. At least in my case, they will be discarded.
TUrns out that the it is easy to filter the events in set_field() with no performance penalty.

EDIT: I think that in a couple of hours I will have code you can test.
chaley is offline   Reply With Quote
Old 09-13-2021, 08:40 AM   #690
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,453
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Here are changes to make set_field() not signal dirty books if nothing actually changed. If they work for you then I will make a pull request to give them to Kovid. The changes in formatter_functions aren't part of the main changes, but instead make testing for being in the gui more robust.

My test function does set_metadata(get_metadata()) on evey book in the
Code:
target library. Run it with calibre-debug -e test.py path-to-library
Note that it really does update metadata so you should keep a backup if you want repeatable tests. For example, in one of my libraries setting the comments field did some cleanup so a change was signaled. On the second run no cleanup was needed and no change was signaled.

I also checked the changes using the calibre test suite.
Attached Files
File Type: zip py_files_for_test.zip (47.6 KB, 304 views)
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Action Chains Resources capink Plugins 78 08-05-2025 04:01 AM
[Editor Plugin] Editor Chains capink Plugins 106 06-17-2025 05:36 PM
[GUI Plugin] Noosfere_util, a companion plugin to noosfere DB lrpirlet Plugins 2 08-18-2022 03:15 PM
[GUI Plugin] Save Virtual Libraries To Column (GUI) chaley Plugins 14 04-04-2021 05:25 AM


All times are GMT -4. The time now is 02:29 PM.


MobileRead.com is a privately owned, operated and funded community.