View Single Post
Old 03-19-2023, 01:29 PM   #25
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 Wiggo View Post
Is there any difference in terms of e.g. perfomance between the 3?
Which one would you choose?
The Python templates are *much* faster than the GPM templates. I would pick one of them. However, that might affect how you can maintain them.
Quote:
Edit: ahh, with python the view is always cleared.
The templates I provided don't take into consideration the fix I made (in source but not released). They both will clear a virtual library. The search version shows only the requested book (the result of the search).

Given my fix, I would use a modified version of the first template that generates show-book links. It is functionally equivalent to the original GPM template, including not clearing searches, but much faster.
Code:
python:
def evaluate(book, context):
	cache = context.db.new_api
	ids = book.get('#mytextmult', [])
	answer = []
	for id_ in ids:
		if cache.has_id(int(id_)):
			answer.append(f'<a href="calibre://show-book/_/{id_}">{id_}</a>')
		else:
			answer.append(f"Book id {id_} doesn't exist")
	return ', '.join(answer)
chaley is offline   Reply With Quote