Experimental db caching for pisi
This commit is contained in:
@@ -62,6 +62,10 @@ def _cleanup():
|
||||
if filesdb.is_initialized():
|
||||
filesdb.close()
|
||||
|
||||
installdb = pisi.db.installdb.InstallDB()
|
||||
if installdb.is_initialized():
|
||||
installdb.close()
|
||||
|
||||
if ctx.build_leftover and os.path.exists(ctx.build_leftover):
|
||||
os.unlink(ctx.build_leftover)
|
||||
|
||||
|
||||
@@ -670,12 +670,14 @@ def __update_repo(repo, force=False):
|
||||
repouri = repodb.get_repo(repo).indexuri.get_uri()
|
||||
try:
|
||||
index.read_uri_of_repo(repouri, repo)
|
||||
pisi.db.packagedb.PackageDB().cache_flush()
|
||||
pisi.db.historydb.HistoryDB().update_repo(repo, repouri, "update")
|
||||
except pisi.file.AlreadyHaveException, e:
|
||||
ctx.ui.info(_('%s repository information is up-to-date.') % repo)
|
||||
if force:
|
||||
ctx.ui.info(_('Updating database at any rate as requested'))
|
||||
index.read_uri_of_repo(repouri, repo, force = force)
|
||||
pisi.db.packagedb.PackageDB().cache_flush()
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import pisi.db.lazydb as lazydb
|
||||
class ComponentDB(lazydb.LazyDB):
|
||||
|
||||
def init(self):
|
||||
self.cacheable = True
|
||||
|
||||
component_nodes = {}
|
||||
component_packages = {}
|
||||
|
||||
@@ -65,6 +65,8 @@ class InstallInfo:
|
||||
class InstallDB(lazydb.LazyDB):
|
||||
|
||||
def init(self):
|
||||
self.cacheable = True
|
||||
|
||||
self.installed_db = self.__generate_installed_pkgs()
|
||||
self.confing_pending_db = self.__generate_config_pending()
|
||||
self.rev_deps_db = self.__generate_revdeps()
|
||||
@@ -192,7 +194,7 @@ class InstallDB(lazydb.LazyDB):
|
||||
def add_package(self, pkginfo):
|
||||
self.installed_db[pkginfo.name] = "%s-%s" % (pkginfo.version, pkginfo.release)
|
||||
self.__add_to_revdeps(pkginfo.name, self.rev_deps_db)
|
||||
|
||||
|
||||
def remove_package(self, package_name):
|
||||
if self.installed_db.has_key(package_name):
|
||||
del self.installed_db[package_name]
|
||||
@@ -219,3 +221,6 @@ class InstallDB(lazydb.LazyDB):
|
||||
return os.path.join(ctx.config.packages_dir(), "%s-%s" % (package, self.installed_db[package]))
|
||||
|
||||
raise Exception(_('Package %s is not installed') % package)
|
||||
|
||||
def close(self):
|
||||
self.cache_save()
|
||||
|
||||
+23
-3
@@ -10,6 +10,8 @@
|
||||
# Please read the COPYING file.
|
||||
#
|
||||
|
||||
import os
|
||||
import cPickle
|
||||
import time
|
||||
import pisi.context as ctx
|
||||
|
||||
@@ -26,11 +28,29 @@ class LazyDB(Singleton):
|
||||
|
||||
def is_initialized(self):
|
||||
return self.initialized
|
||||
|
||||
|
||||
def cache_save(self):
|
||||
if os.access("/var/cache/pisi", os.W_OK) and self.__class__._the_instance.__dict__.has_key("cacheable"):
|
||||
cPickle.dump(self.__class__._the_instance.__dict__,
|
||||
file('/var/cache/pisi/%s.cache' % self.__class__.__name__.lower(), 'wb'), 1)
|
||||
|
||||
def cache_load(self):
|
||||
if os.path.exists("/var/cache/pisi/%s.cache" % self.__class__.__name__.lower()):
|
||||
self.__class__._the_instance.__dict__ = cPickle.load(file('/var/cache/pisi/%s.cache' % self.__class__.__name__.lower(), 'rb'))
|
||||
return True
|
||||
return False
|
||||
|
||||
def cache_flush(self):
|
||||
cache_file = "/var/cache/pisi/%s.cache" % self.__class__.__name__.lower()
|
||||
if os.path.exists(cache_file):
|
||||
os.unlink(cache_file)
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if not self.initialized:
|
||||
if not attr == "__setstate__" and not self.initialized:
|
||||
start = time.time()
|
||||
self.init()
|
||||
if not self.cache_load():
|
||||
self.init()
|
||||
self.cache_save()
|
||||
end = time.time()
|
||||
ctx.ui.debug("%s initialized in %s." % (self.__class__.__name__, end - start))
|
||||
self.initialized = True
|
||||
|
||||
@@ -36,9 +36,10 @@ import pisi.db.lazydb as lazydb
|
||||
class PackageDB(lazydb.LazyDB):
|
||||
|
||||
def init(self):
|
||||
self.cacheable = True
|
||||
|
||||
self.__package_nodes = {} # Packages
|
||||
self.__revdeps = {} # Reverse dependencies
|
||||
self.__revdeps = {} # Reverse dependencies
|
||||
self.__obsoletes = {} # Obsoletes
|
||||
self.__replaces = {} # Replaces
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import pisi.db.lazydb as lazydb
|
||||
class SourceDB(lazydb.LazyDB):
|
||||
|
||||
def init(self):
|
||||
self.cacheable = True
|
||||
|
||||
self.__source_nodes = {}
|
||||
self.__pkgstosrc = {}
|
||||
|
||||
Reference in New Issue
Block a user