From 90b6352d0a5d08dc7feabcfde92653dd1f6e324b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 24 Feb 2010 12:48:00 +0000 Subject: [PATCH] * Do registerValidPaths() in one transaction, which is much faster. E.g. it cuts the runtime of the referrers test from 50s to 23s. --- src/libstore/local-store.cc | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 8e5448446..6e8082776 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -765,39 +765,19 @@ Hash LocalStore::queryPathHash(const Path & path) } -static void dfsVisit(std::map & infos, - const Path & path, PathSet & visited, Paths & sorted) -{ - if (visited.find(path) != visited.end()) return; - visited.insert(path); - - ValidPathInfo & info(infos[path]); - - foreach (PathSet::iterator, i, info.references) - if (infos.find(*i) != infos.end()) - dfsVisit(infos, *i, visited, sorted); - - sorted.push_back(path); -} - - void LocalStore::registerValidPaths(const ValidPathInfos & infos) { - std::map infosMap; + SQLiteTxn txn(db); - /* Sort the paths topologically under the references relation, so - that if path A is referenced by B, then A is registered before - B. */ - foreach (ValidPathInfos::const_iterator, i, infos) - infosMap[i->path] = *i; + foreach (ValidPathInfos::const_iterator, i, infos) addValidPath(*i); - PathSet visited; - Paths sorted; - foreach (ValidPathInfos::const_iterator, i, infos) - dfsVisit(infosMap, i->path, visited, sorted); + foreach (ValidPathInfos::const_iterator, i, infos) { + unsigned long long referrer = queryPathInfo(i->path).id; + foreach (PathSet::iterator, j, i->references) + addReference(referrer, queryPathInfo(*j).id); + } - foreach (Paths::iterator, i, sorted) - registerValidPath(infosMap[*i]); + txn.commit(); }