From 90b6352d0a5d08dc7feabcfde92653dd1f6e324b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 24 Feb 2010 12:48:00 +0000 Subject: * 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 | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) (limited to 'src/libstore') diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 8e5448446065..6e8082776dd0 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) +void LocalStore::registerValidPaths(const ValidPathInfos & infos) { - if (visited.find(path) != visited.end()) return; - visited.insert(path); - - ValidPathInfo & info(infos[path]); + SQLiteTxn txn(db); - foreach (PathSet::iterator, i, info.references) - if (infos.find(*i) != infos.end()) - dfsVisit(infos, *i, visited, sorted); - - sorted.push_back(path); -} + foreach (ValidPathInfos::const_iterator, i, infos) addValidPath(*i); + 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); + } -void LocalStore::registerValidPaths(const ValidPathInfos & infos) -{ - std::map infosMap; - - /* 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; - - PathSet visited; - Paths sorted; - foreach (ValidPathInfos::const_iterator, i, infos) - dfsVisit(infosMap, i->path, visited, sorted); - - foreach (Paths::iterator, i, sorted) - registerValidPath(infosMap[*i]); + txn.commit(); } -- cgit 1.4.1