From: Michael Tremer Date: Sun, 20 Nov 2011 11:39:39 +0000 (+0100) Subject: Create a local SOLV file that contains all package information. X-Git-Tag: 0.9.18~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4d7f8f1f1fc635b38c3cfca765bfc5b3328e53a;p=pakfire.git Create a local SOLV file that contains all package information. Reading the sqlite is very slow (however) and as we like to have a very great user experience, we can cache all information that is needed by the solver. For anything else, the full sqlite database is kept and we rely on that in the first place. --- diff --git a/python/pakfire/constants.py b/python/pakfire/constants.py index 21819198e..e396888be 100644 --- a/python/pakfire/constants.py +++ b/python/pakfire/constants.py @@ -42,6 +42,7 @@ LOCAL_TMP_PATH = "/var/tmp" PACKAGES_DB_DIR = "var/lib/pakfire" PACKAGES_DB = os.path.join(PACKAGES_DB_DIR, "packages.db") +PACKAGES_SOLV = os.path.join(PACKAGES_DB_DIR, "packages.solv") REPOSITORY_DB = "index.db" BUFFER_SIZE = 102400 diff --git a/python/pakfire/repository/base.py b/python/pakfire/repository/base.py index 56ece2ea1..e606826c1 100644 --- a/python/pakfire/repository/base.py +++ b/python/pakfire/repository/base.py @@ -127,6 +127,12 @@ class RepositoryFactory(object): assert self.index self.index.clear() + def commit(self): + """ + Commit repository data to disk. + """ + self.index.commit() + def dump(self, long=False, filelist=False): dumps = [] # Dump all package information of the packages in this repository. diff --git a/python/pakfire/repository/index.py b/python/pakfire/repository/index.py index a73fa76a9..c43303f32 100644 --- a/python/pakfire/repository/index.py +++ b/python/pakfire/repository/index.py @@ -83,6 +83,12 @@ class Index(object): """ self.solver_repo.write(filename) + def commit(self): + """ + Commit index data to disk. + """ + pass + def create_relation(self, *args, **kwargs): return self.pakfire.create_relation(*args, **kwargs) @@ -407,6 +413,19 @@ class IndexLocal(Index): def init(self): self.db = database.DatabaseLocal(self.pakfire, self.repo) + if os.path.exists(PACKAGES_SOLV): + self.read(PACKAGES_SOLV) + + def commit(self): + # Write SOLV cache file. + filename = os.path.join(self.pakfire.path, PACKAGES_SOLV) + + dirname = os.path.dirname(filename) + if not os.path.exists(dirname): + os.makedirs(dirname) + + self.write(filename) + def check(self): # XXX Create the database and lock it or something. pass diff --git a/python/pakfire/transaction.py b/python/pakfire/transaction.py index 11a05efe3..ec54b1c33 100644 --- a/python/pakfire/transaction.py +++ b/python/pakfire/transaction.py @@ -203,6 +203,11 @@ class Transaction(object): return transaction + @property + def local(self): + # Shortcut to local repository. + return self.pakfire.repos.local + def add(self, action_name, pkg): assert isinstance(pkg, packages.SolvPackage), pkg @@ -427,5 +432,8 @@ class Transaction(object): log.info("") + # Commit repository metadata. + self.local.commit() + # Call sync to make sure all buffers are written to disk. sync()