View Single Post
Old 07-29-2013, 10:43 PM   #60
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,779
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
@davidfor: From Peter's description it looks to me like updating the database for a large number of books is slower with the new backend in your plugin.

This is because the new backend operates in auto-commit mode. That is after every change, the database is committed. So if you are making changes to a lot of database records, you should do them in bulk. For example, to change the the #xyz field in for a number of records, in the old db you would do:

Code:
for book_id in book_ids:
   db.set_custom(book_id, val, label='xyz', commit=False)
db.commit()
With the new db you should instead do:
Code:
if hasattr(db, 'new_api'):
   db.new_api.set_field('#xyz', {book_id:val for book_id in book_ids})
else:
    # do it the old way
kovidgoyal is offline   Reply With Quote