View Single Post
Old 03-24-2021, 05:22 PM   #426
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,211
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
I thought of this. My concern was that the template functions explode string lists, which is *very slow* for large lists such as thousands of books. If you (we) go down this road then we might want to introduce a specific type and associated functions for book lists that uses a python set underneath. I think this would be OK in the specific case of lists (sets) of numbers. I need to look at this if we want to try it.
I made a chain (attached below) to test this by having a template store the ids to chain variable, and have a second custom action read the variable and convert to python list. You have to add this custom action through the module editor before using the attached chain:

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

class MyTestAction(ChainAction):

    name = 'My Test Action'

    def run(self, gui, settings, chain):
        book_ids = chain.chain_vars['book_ids']
        book_ids = book_ids.split(',')
        book_ids = [int(book_id) for book_id in book_ids]
        print(book_ids)
It is running blindingly fast (0.3 seconds on a 52000 books library). Much faster than the usual call to calculate book ids from selected rows.


Quote:
Originally Posted by chaley View Post
My idea was to use the key to the book_vars dict, which as far as I can tell is always the book id (I think book_vars is {book_id: {var_name: value}}).
You are correct. The dictionary keys (book_ids) can be accessed from any action. I was talking about accessing them from a template.


Quote:
Originally Posted by chaley View Post
You (we) also need to ensure that the complexity doesn't rise beyond the "usable point". That is a problem I have had with the template language for the last 10 years.
I think that functional validation is hopeless. Who knows what the "template program" is supposed to do, and who knows if it is doing it correctly? Only the user. Verifying syntax is about the best one can do, unless some test mechanism is introduced where the action is run but nothing is permanent. How to do that in a chain of actions escapes me.
You are probably right about validation. But still we need to make a decision whether to abort the action or the whole chain.

Edit: modify custom action make it convert book_ids to integer values.
Attached Files
File Type: zip chain.zip (470 Bytes, 842 views)

Last edited by capink; 03-24-2021 at 05:31 PM.
capink is online now   Reply With Quote