Multiple content.db support
This commit is contained in:
parent
6ac4c8c9cb
commit
bc875b396b
2 changed files with 16 additions and 6 deletions
|
@ -5,9 +5,9 @@ from Config import config
|
|||
|
||||
|
||||
class ContentDb(Db):
|
||||
def __init__(self):
|
||||
def __init__(self, path):
|
||||
self.version = 4
|
||||
super(ContentDb, self).__init__({"db_name": "ContentDb"}, "%s/content.db" % config.data_dir)
|
||||
super(ContentDb, self).__init__({"db_name": "ContentDb"}, path)
|
||||
self.foreign_keys = True
|
||||
self.checkTables()
|
||||
self.site_ids = {}
|
||||
|
@ -112,5 +112,14 @@ class ContentDb(Db):
|
|||
)
|
||||
return {row["inner_path"]: row["modified"] for row in res}
|
||||
|
||||
content_dbs = {}
|
||||
|
||||
content_db = ContentDb()
|
||||
|
||||
def getContentDb(path=None):
|
||||
if not path:
|
||||
path = "%s/content.db" % config.data_dir
|
||||
if path not in content_dbs:
|
||||
content_dbs[path] = ContentDb(path)
|
||||
return content_dbs[path]
|
||||
|
||||
getContentDb() # Pre-connect to default one
|
||||
|
|
|
@ -11,11 +11,11 @@ class ContentDbDict(dict):
|
|||
self.site_address = site.address
|
||||
self.cached_keys = []
|
||||
self.log = self.site.log
|
||||
self.db = ContentDb.content_db
|
||||
self.db = ContentDb.getContentDb()
|
||||
self.db_id = self.db.needSite(site.address)
|
||||
self.num_loaded = 0
|
||||
super(ContentDbDict, self).__init__(self.db.loadDbDict(site.address)) # Load keys from database
|
||||
self.log.debug("ContentDb init: %.3fs, found files: %s" % (time.time() - s, len(self)))
|
||||
self.log.debug("ContentDb init: %.3fs, found files: %s, sites: %s" % (time.time() - s, len(self), len(self.db.site_ids)))
|
||||
|
||||
def loadItem(self, key):
|
||||
try:
|
||||
|
@ -77,7 +77,8 @@ class ContentDbDict(dict):
|
|||
|
||||
def items(self):
|
||||
back = []
|
||||
for key, val in dict.iteritems(self):
|
||||
for key in dict.keys(self):
|
||||
val = self[key]
|
||||
if not val:
|
||||
try:
|
||||
val = self.loadItem(key)
|
||||
|
|
Loading…
Reference in a new issue