diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-07-18T14·47-0400 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-07-18T14·47-0400 |
commit | fe241ece2932492866693d268d02a7912e766ac7 (patch) | |
tree | 2cb24a4d45f563e32946bf34d878969bd05263ec /src/libstore/local-store.cc | |
parent | a6f348599c94d8a5f7b41c7d8e43658dc6407be7 (diff) | |
parent | ccc52adfb2121ade510d35dc9b91193af9fa731e (diff) |
Merge branch 'master' into no-manifests
Diffstat (limited to 'src/libstore/local-store.cc')
-rw-r--r-- | src/libstore/local-store.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 6e4cd053c859..aa21774df4a7 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -405,6 +405,10 @@ void LocalStore::openDB(bool create) "select v.id, v.path from DerivationOutputs d join ValidPaths v on d.drv = v.id where d.path = ?;"); stmtQueryDerivationOutputs.create(db, "select id, path from DerivationOutputs where drv = ?;"); + // Use "path >= ?" with limit 1 rather than "path like '?%'" to + // ensure efficient lookup. + stmtQueryPathFromHashPart.create(db, + "select path from ValidPaths where path >= ? limit 1;"); } @@ -874,6 +878,26 @@ StringSet LocalStore::queryDerivationOutputNames(const Path & path) } +Path LocalStore::queryPathFromHashPart(const string & hashPart) +{ + if (hashPart.size() != 32) throw Error("invalid hash part"); + + SQLiteTxn txn(db); + + Path prefix = nixStore + "/" + hashPart; + + SQLiteStmtUse use(stmtQueryPathFromHashPart); + stmtQueryPathFromHashPart.bind(prefix); + + int res = sqlite3_step(stmtQueryPathFromHashPart); + if (res == SQLITE_DONE) return ""; + if (res != SQLITE_ROW) throwSQLiteError(db, "finding path in database"); + + const char * s = (const char *) sqlite3_column_text(stmtQueryPathFromHashPart, 0); + return s && prefix.compare(0, prefix.size(), s, prefix.size()) == 0 ? s : ""; +} + + void LocalStore::startSubstituter(const Path & substituter, RunningSubstituter & run) { if (run.pid != -1) return; |