View Single Post
Old 09-18-2014, 04:29 PM   #14
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
def force_refresh_of_cache(self, books_to_refresh):

I have answered my own question posed in the original post, and have documented it here. Be careful.

from calibre.db.cache import Cache as dbcache
#------------------------------------------

def force_refresh_of_cache(self, books_to_refresh):

# Use with *great discretion* to avoid bad things happening.

# Do this only when an annoying restart would otherwise be indicated and required
# due to the update of custom column metadata done *outside* of the Calibre API, i.e.,
# db = self.gui.current_db.new_api #see: http://manual.calibre-ebook.com/db_api.html

# NO jobs or other background tasks should be running when you execute this.

# 'books_to_refresh' is a simple list of integers (i.e., books), and is not a list of dicts (e.g., {'calibre_id': 12345} )
# To get a set of all books in the library (required as a parameter to this function):
# db = self.gui.current_db.new_api #see: http://manual.calibre-ebook.com/db_api.html
# books_to_refresh_frozenset = db.all_book_ids()
# Then, you must create books_to_refresh as a simple list from the frozenset and pass it as the only parameter to here.
# After this executes, the next time the user clicks on the gui, it will show the refreshed metadata.

backend = self.gui.library_view.model().db.backend
mydbcache = dbcache(self.gui.library_view.model().db.backend)
mydbcache.init() #refreshes the cache from the physical metadata.db. refer to: >src>calibre>db>cache.py
self.gui.library_view.model().refresh_ids(list(boo ks_to_refresh)) #refreshes the gui from the cache
# class EditMetadataAction in src>calibre>gui2>actions>edit_metadata.py
self.gui.tags_view.recount() #refreshes the tag browser
# class TagsView in src>calibre>gui2>tag_browser>view.py


#-------------------

Best of luck.


DaltonST is offline   Reply With Quote