diff --git a/src/Content/ContentDb.py b/src/Content/ContentDb.py index 015c63e6..09870ffc 100644 --- a/src/Content/ContentDb.py +++ b/src/Content/ContentDb.py @@ -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 diff --git a/src/Content/ContentDbDict.py b/src/Content/ContentDbDict.py index 2b1bc8f2..131271f5 100644 --- a/src/Content/ContentDbDict.py +++ b/src/Content/ContentDbDict.py @@ -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)