View Single Post
Old 04-18-2021, 04:27 AM   #59
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,475
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Also, is there any particular advantages of an template rule with several if statements vs. several non-composed basic rules? The context is for my Cleanup VL:
[...]
I've got a template half-made but I am not sure if it is worth.
It goes both ways.

First, note that all rules are templates. The templates for basic rules are generated by calibre.

So ...
  • A sequence of basic rules will be slightly faster if the first rule succeeds almost all the time, e.g., 99%.
  • A single template will be faster if the succeeding rule isn't usually the first because it avoids the overhead of sequentially executing the basic templates looking for a result.
  • There are many situations where an advanced rule is needed, such as when you need the "or" of conditions. Basic rules implement 'and'.
  • Depending on what you are doing, one technique or the other might be easier to understand and maintain.
  • And finally, you might prefer one over the other.
FWIW: a sequence of non-composed rules is equivalent to a single template that returns the first qualifying result. For example, assume you want a 'foo.png' icon on the author column if the author is "Joe Blogs" but a 'bar.png' icon if the author is 'Fred Flintstone'. This could be done with two non-composed basic rules, or with this template:
Code:
program:
	if str_in_list($authors, '&', 'Joe Blogs', '1', '') then return 'foo.png' fi;
	if str_in_list($authors, '&', 'Fred Flintstone', '1', '') then return 'bar.png' fi
The template is easier if the searched field is comma separated, for example tags, because you can use the 'inlist' operator. Assuming you are searching for 'ondevice' or 'bar', the template would be:
Code:
program:
	if '^ondevice$' inlist $tags then return 'foo.png' fi;
	if '^bar$' inlist $tags then return 'bar.png' fi;
chaley is offline   Reply With Quote