![]() |
#676 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#677 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,453
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
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(). |
![]() |
![]() |
![]() |
#678 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
#679 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,453
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#680 |
Junior Member
![]() 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.
|
![]() |
![]() |
![]() |
#681 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
Last edited by ownedbycats; 09-11-2021 at 06:51 PM. |
![]() |
![]() |
![]() |
#682 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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) Last edited by capink; 09-12-2021 at 09:51 AM. |
![]() |
![]() |
![]() |
#683 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
|
|
![]() |
![]() |
![]() |
#684 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
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? |
|
![]() |
![]() |
![]() |
#685 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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)) |
![]() |
![]() |
![]() |
#686 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
#687 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,453
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
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_)) |
|
![]() |
![]() |
![]() |
#688 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
I don't think it is worth filtering out. At least in my case, they will be discarded. |
|
![]() |
![]() |
![]() |
#689 | ||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,453
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
EDIT: I think that in a couple of hours I will have code you can test. |
||
![]() |
![]() |
![]() |
#690 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 I also checked the changes using the calibre test suite. |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |