about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-11T15·08-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-11T15·08-0400
commit58ef4d9a95584fb89ebcf6222fbac6e698aa6b0b (patch)
tree1e01e79b406f59b06397a24b4b86f1c6fa5fc308
parent667d5f1936616dc829f9f92f8e5d5141ba5285a7 (diff)
Add a function queryValidPaths()
queryValidPaths() combines multiple calls to isValidPath() in one.
This matters when using the Nix daemon because it reduces latency.
For instance, on "nix-env -qas \*" it reduces execution time from 5.7s
to 4.7s (which is indistinguishable from the non-daemon case).
-rw-r--r--src/libstore/local-store.cc9
-rw-r--r--src/libstore/local-store.hh2
-rw-r--r--src/libstore/remote-store.cc17
-rw-r--r--src/libstore/remote-store.hh2
-rw-r--r--src/libstore/store-api.hh3
-rw-r--r--src/libstore/worker-protocol.hh1
-rw-r--r--src/nix-env/nix-env.cc9
-rw-r--r--src/nix-worker/nix-worker.cc9
8 files changed, 49 insertions, 3 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 89c5279b1b6e..e3d23fdfbcb7 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -744,6 +744,15 @@ bool LocalStore::isValidPath(const Path & path)
 }
 
 
+PathSet LocalStore::queryValidPaths(const PathSet & paths)
+{
+    PathSet res;
+    foreach (PathSet::const_iterator, i, paths)
+        if (isValidPath(*i)) res.insert(*i);
+    return res;
+}
+
+
 PathSet LocalStore::queryAllValidPaths()
 {
     SQLiteStmt stmt;
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index d24c2da0ee17..7398c1b9e5e0 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -99,6 +99,8 @@ public:
     
     bool isValidPath(const Path & path);
 
+    PathSet queryValidPaths(const PathSet & paths);
+    
     PathSet queryAllValidPaths();
     
     ValidPathInfo queryPathInfo(const Path & path);
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 04a9e28c9007..0cd29c5751d2 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -217,6 +217,23 @@ bool RemoteStore::isValidPath(const Path & path)
 }
 
 
+PathSet RemoteStore::queryValidPaths(const PathSet & paths)
+{
+    if (GET_PROTOCOL_MINOR(daemonVersion) < 12) {
+        PathSet res;
+        foreach (PathSet::const_iterator, i, paths)
+            if (isValidPath(*i)) res.insert(*i);
+        return res;
+    } else {
+        openConnection();
+        writeInt(wopQueryValidPaths, to);
+        writeStrings(paths, to);
+        processStderr();
+        return readStorePaths<PathSet>(from);
+    }
+}
+
+
 PathSet RemoteStore::queryAllValidPaths()
 {
     openConnection();
diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh
index 6e92498377dd..2668fe25689f 100644
--- a/src/libstore/remote-store.hh
+++ b/src/libstore/remote-store.hh
@@ -27,6 +27,8 @@ public:
     
     bool isValidPath(const Path & path);
 
+    PathSet queryValidPaths(const PathSet & paths);
+    
     PathSet queryAllValidPaths();
     
     ValidPathInfo queryPathInfo(const Path & path);
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 802591766af7..13dcd9269d3a 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -113,6 +113,9 @@ public:
     /* Check whether a path is valid. */ 
     virtual bool isValidPath(const Path & path) = 0;
 
+    /* Query which of the given paths is valid. */
+    virtual PathSet queryValidPaths(const PathSet & paths) = 0;
+
     /* Query the set of all valid paths. */
     virtual PathSet queryAllValidPaths() = 0;
 
diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh
index cacd56f14edd..b34ad484613d 100644
--- a/src/libstore/worker-protocol.hh
+++ b/src/libstore/worker-protocol.hh
@@ -41,6 +41,7 @@ typedef enum {
     wopImportPaths = 27,
     wopQueryDerivationOutputNames = 28,
     wopQuerySubstitutablePathInfos = 29,
+    wopQueryValidPaths = 30,
 } WorkerOp;
 
 
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index 2fd4246dd297..91b82c0d09e6 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -932,6 +932,7 @@ static void opQuery(Globals & globals,
 
     /* Query which paths have substitutes. */
     SubstitutablePathInfos subs;
+    PathSet validPaths;
     if (printStatus) {
         PathSet paths;
         foreach (vector<DrvInfo>::iterator, i, elems2)
@@ -941,6 +942,7 @@ static void opQuery(Globals & globals,
                 printMsg(lvlTalkative, format("skipping derivation named `%1%' which gives an assertion failure") % i->name);
                 i->setFailed();
             }
+        validPaths = store->queryValidPaths(paths);
         store->querySubstitutablePathInfos(paths, subs);
     }
 
@@ -966,9 +968,10 @@ static void opQuery(Globals & globals,
             XMLAttrs attrs;
 
             if (printStatus) {
-                bool hasSubs = subs.find(i->queryOutPath(globals.state)) != subs.end();
-                bool isInstalled = installed.find(i->queryOutPath(globals.state)) != installed.end();
-                bool isValid = store->isValidPath(i->queryOutPath(globals.state));
+                Path outPath = i->queryOutPath(globals.state);
+                bool hasSubs = subs.find(outPath) != subs.end();
+                bool isInstalled = installed.find(outPath) != installed.end();
+                bool isValid = validPaths.find(outPath) != validPaths.end();
                 if (xmlOutput) {
                     attrs["installed"] = isInstalled ? "1" : "0";
                     attrs["valid"] = isValid ? "1" : "0";
diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc
index e786318ad45f..4d22f788595c 100644
--- a/src/nix-worker/nix-worker.cc
+++ b/src/nix-worker/nix-worker.cc
@@ -297,6 +297,15 @@ static void performOp(unsigned int clientVersion,
         break;
     }
 
+    case wopQueryValidPaths: {
+        PathSet paths = readStorePaths<PathSet>(from);
+        startWork();
+        PathSet res = store->queryValidPaths(paths);
+        stopWork();
+        writeStrings(res, to);
+        break;
+    }
+
     case wopHasSubstitutes: {
         Path path = readStorePath(from);
         startWork();