When bulk downloading metadata for more than 100 books ata time, automatically split up the download into batches of 100. Fixes #828373 (Split Bulk Metadata download job into smaller jobs)

This commit is contained in:
Kovid Goyal 2011-08-18 11:26:05 -06:00
parent 127b517977
commit 1d74d7cc93

View File

@ -89,6 +89,15 @@ class ConfirmDialog(QDialog):
self.identify = False self.identify = False
self.accept() self.accept()
def split_jobs(ids, batch_size=100):
ans = []
ids = list(ids)
while ids:
jids = ids[:batch_size]
ans.append(jids)
ids = ids[batch_size:]
return ans
def start_download(gui, ids, callback): def start_download(gui, ids, callback):
d = ConfirmDialog(ids, gui) d = ConfirmDialog(ids, gui)
ret = d.exec_() ret = d.exec_()
@ -96,11 +105,13 @@ def start_download(gui, ids, callback):
if ret != d.Accepted: if ret != d.Accepted:
return return
job = ThreadedJob('metadata bulk download', for batch in split_jobs(ids):
_('Download metadata for %d books')%len(ids), job = ThreadedJob('metadata bulk download',
download, (ids, gui.current_db, d.identify, d.covers), {}, callback) _('Download metadata for %d books')%len(batch),
gui.job_manager.run_threaded_job(job) download, (batch, gui.current_db, d.identify, d.covers), {}, callback)
gui.job_manager.run_threaded_job(job)
gui.status_bar.show_message(_('Metadata download started'), 3000) gui.status_bar.show_message(_('Metadata download started'), 3000)
# }}} # }}}
def get_job_details(job): def get_job_details(job):