mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Implement indexing speed option for calibredb
This commit is contained in:
parent
9cbb385b1c
commit
c099abb2e3
@ -69,19 +69,17 @@ Control the fts indexing process.
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
help=_('Wait till all books are indexed, showing indexing progress periodically')
|
help=_('Wait till all books are indexed, showing indexing progress periodically')
|
||||||
)
|
)
|
||||||
|
parser.add_option(
|
||||||
|
'--indexing-speed',
|
||||||
|
default='',
|
||||||
|
choices=('fast', 'slow', ''),
|
||||||
|
help=_('The speed of indexing. Use fast for fast indexing using all your computers resources'
|
||||||
|
' and slow for less resource intensive indexing. Note that the speed is reset to slow on every invocation.')
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def run_job(dbctx, which, adata=None):
|
def local_wait_for_completion(db, indexing_speed):
|
||||||
try:
|
|
||||||
return dbctx.run('fts_index', which, adata)
|
|
||||||
except Exception as e:
|
|
||||||
if getattr(e, 'suppress_traceback', False):
|
|
||||||
raise SystemExit(str(e))
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
def local_wait_for_completion(db):
|
|
||||||
from calibre.db.listeners import EventType
|
from calibre.db.listeners import EventType
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
|
|
||||||
@ -96,6 +94,8 @@ def local_wait_for_completion(db):
|
|||||||
print('\r\x1b[K' + _('{} of {} book files indexed, {}').format(total-left, total, indexing_progress_time_left()), flush=True, end=' ...')
|
print('\r\x1b[K' + _('{} of {} book files indexed, {}').format(total-left, total, indexing_progress_time_left()), flush=True, end=' ...')
|
||||||
|
|
||||||
db.add_listener(listen)
|
db.add_listener(listen)
|
||||||
|
if indexing_speed:
|
||||||
|
db.set_fts_speed(slow=indexing_speed == 'slow')
|
||||||
l, t = db.fts_indexing_progress()
|
l, t = db.fts_indexing_progress()
|
||||||
if l < 1:
|
if l < 1:
|
||||||
return
|
return
|
||||||
@ -113,6 +113,17 @@ def main(opts, args, dbctx):
|
|||||||
dbctx.option_parser.print_help()
|
dbctx.option_parser.print_help()
|
||||||
raise SystemExit(_('Error: You must specify the indexing action'))
|
raise SystemExit(_('Error: You must specify the indexing action'))
|
||||||
action = args[0]
|
action = args[0]
|
||||||
|
adata = {}
|
||||||
|
|
||||||
|
def run_job(dbctx, which, **kw):
|
||||||
|
data = adata.copy()
|
||||||
|
data.update(kw)
|
||||||
|
try:
|
||||||
|
return dbctx.run('fts_index', which, data)
|
||||||
|
except Exception as e:
|
||||||
|
if getattr(e, 'suppress_traceback', False):
|
||||||
|
raise SystemExit(str(e))
|
||||||
|
raise
|
||||||
|
|
||||||
if action == 'status':
|
if action == 'status':
|
||||||
s = run_job(dbctx, 'status')
|
s = run_job(dbctx, 'status')
|
||||||
@ -150,7 +161,7 @@ def main(opts, args, dbctx):
|
|||||||
if dbctx.is_remote:
|
if dbctx.is_remote:
|
||||||
raise NotImplementedError('TODO: Implement waiting for completion via polling')
|
raise NotImplementedError('TODO: Implement waiting for completion via polling')
|
||||||
else:
|
else:
|
||||||
local_wait_for_completion(dbctx.db.new_api)
|
local_wait_for_completion(dbctx.db.new_api, opts.indexing_speed)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.excepthook = lambda *a: None
|
sys.excepthook = lambda *a: None
|
||||||
raise
|
raise
|
||||||
|
Loading…
x
Reference in New Issue
Block a user