View Single Post
Old 04-21-2023, 05:10 AM   #590
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,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by BetterRed View Post
Suggestion: an has_data function, analogue of has_cover.
Quote:
Originally Posted by ownedbycats View Post
This is something I would use.
Such a function must query the file system, so it won't be fast. My suspicion is that you want to use this for column icons, which may make the performance unacceptable.

Implementation choices:
  1. Fastest would be to check if "data/" exists, regardless of whether or not there is anything in it. I suspect the false positive rate would be unacceptable.
  2. Next would be to check if "data/" contains anything.
  3. Equally performant as 2, or perhaps I should say non-performant, would be to permit checking if particular files exist by matching the list of files against a regular expression.

This python template does check #2. Make it a stored template and try it to see if it is sufficiently performant.
Code:
python:
def evaluate(book, context):
	db = context.db.new_api
	files = db.list_extra_files_matching(book.id)
	return '1' if files else ''
chaley is offline   Reply With Quote