forked from lix-project/lix
* Do registerValidPaths() in one transaction, which is much faster.
E.g. it cuts the runtime of the referrers test from 50s to 23s.
This commit is contained in:
parent
fae0427324
commit
90b6352d0a
1 changed files with 8 additions and 28 deletions
|
@ -765,39 +765,19 @@ Hash LocalStore::queryPathHash(const Path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void dfsVisit(std::map<Path, ValidPathInfo> & 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)
|
void LocalStore::registerValidPaths(const ValidPathInfos & infos)
|
||||||
{
|
{
|
||||||
std::map<Path, ValidPathInfo> infosMap;
|
SQLiteTxn txn(db);
|
||||||
|
|
||||||
/* Sort the paths topologically under the references relation, so
|
foreach (ValidPathInfos::const_iterator, i, infos) addValidPath(*i);
|
||||||
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;
|
foreach (ValidPathInfos::const_iterator, i, infos) {
|
||||||
Paths sorted;
|
unsigned long long referrer = queryPathInfo(i->path).id;
|
||||||
foreach (ValidPathInfos::const_iterator, i, infos)
|
foreach (PathSet::iterator, j, i->references)
|
||||||
dfsVisit(infosMap, i->path, visited, sorted);
|
addReference(referrer, queryPathInfo(*j).id);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Paths::iterator, i, sorted)
|
txn.commit();
|
||||||
registerValidPath(infosMap[*i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue