View Single Post
Old 01-15-2024, 03:21 PM   #90
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,449
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Is there any speed difference basing a virtual library query on a composite column, or on a direct template?

Example:
[...]
Either I can use
#readstatus:"=Backlog"
or
a template search with program: readstatus()=='unread' && 'readinggoal:' in $#admintags
This is very hard to answer without doing timings. Reasons:
  • Composite column values are cached. If the cache is valid then getting the value of a composite by lookup name is extremely fast.
  • The cache is invalided by changes to the database, which can force a recalculation of the value for all the books. Or only affected books. Speed thus depends on the context.
  • Search templates don't use the cache, but do calculate values only when required by the logical expression.
  • In your case the search template is much simpler so in cases where the composite must be recalculated the search will be faster.
So the answer depends on how and where you use it.

Virtual libraries are frequently recomputed even when the db hasn't changed so I expect the composite cache would win.

FWIW: your template can faster by embedding if/then/else instead of duplicating the switch_if condition.
Code:
program:
	status = readstatus();
	times = $$#timesread;

	switch_if(
		status=='currentlyreading', if times ># 0 then 'Currently Rereading' else 'Currently Reading' fi,
		status=='toberead', if times ># 0 then 'To Be Reread' else 'To Be Read' fi,
		status=='read', 'Read',
		status=='unread', if 'readinggoal:' in $#admintags then 'Backlog' else 'Unread' fi,
		status=='didnotfinish', 'Did Not Finish',
		''
	)
I can't test this. I might have made some transcription errors.

If you rather you could use secondary switch_if()s instead of if/then/else. The performance is equivalent given the secondary switch_if()s have only one test expression. As in
Code:
		status=='currentlyreading', switch_if(times ># 0, 'Currently Rereading', 'Currently Reading'),
chaley is offline   Reply With Quote