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).
This commit is contained in:
		
							parent
							
								
									667d5f1936
								
							
						
					
					
						commit
						58ef4d9a95
					
				
					 8 changed files with 49 additions and 3 deletions
				
			
		|  | @ -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() | PathSet LocalStore::queryAllValidPaths() | ||||||
| { | { | ||||||
|     SQLiteStmt stmt; |     SQLiteStmt stmt; | ||||||
|  |  | ||||||
|  | @ -99,6 +99,8 @@ public: | ||||||
|      |      | ||||||
|     bool isValidPath(const Path & path); |     bool isValidPath(const Path & path); | ||||||
| 
 | 
 | ||||||
|  |     PathSet queryValidPaths(const PathSet & paths); | ||||||
|  |      | ||||||
|     PathSet queryAllValidPaths(); |     PathSet queryAllValidPaths(); | ||||||
|      |      | ||||||
|     ValidPathInfo queryPathInfo(const Path & path); |     ValidPathInfo queryPathInfo(const Path & path); | ||||||
|  |  | ||||||
|  | @ -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() | PathSet RemoteStore::queryAllValidPaths() | ||||||
| { | { | ||||||
|     openConnection(); |     openConnection(); | ||||||
|  |  | ||||||
|  | @ -27,6 +27,8 @@ public: | ||||||
|      |      | ||||||
|     bool isValidPath(const Path & path); |     bool isValidPath(const Path & path); | ||||||
| 
 | 
 | ||||||
|  |     PathSet queryValidPaths(const PathSet & paths); | ||||||
|  |      | ||||||
|     PathSet queryAllValidPaths(); |     PathSet queryAllValidPaths(); | ||||||
|      |      | ||||||
|     ValidPathInfo queryPathInfo(const Path & path); |     ValidPathInfo queryPathInfo(const Path & path); | ||||||
|  |  | ||||||
|  | @ -113,6 +113,9 @@ public: | ||||||
|     /* Check whether a path is valid. */  |     /* Check whether a path is valid. */  | ||||||
|     virtual bool isValidPath(const Path & path) = 0; |     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. */ |     /* Query the set of all valid paths. */ | ||||||
|     virtual PathSet queryAllValidPaths() = 0; |     virtual PathSet queryAllValidPaths() = 0; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -41,6 +41,7 @@ typedef enum { | ||||||
|     wopImportPaths = 27, |     wopImportPaths = 27, | ||||||
|     wopQueryDerivationOutputNames = 28, |     wopQueryDerivationOutputNames = 28, | ||||||
|     wopQuerySubstitutablePathInfos = 29, |     wopQuerySubstitutablePathInfos = 29, | ||||||
|  |     wopQueryValidPaths = 30, | ||||||
| } WorkerOp; | } WorkerOp; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -932,6 +932,7 @@ static void opQuery(Globals & globals, | ||||||
| 
 | 
 | ||||||
|     /* Query which paths have substitutes. */ |     /* Query which paths have substitutes. */ | ||||||
|     SubstitutablePathInfos subs; |     SubstitutablePathInfos subs; | ||||||
|  |     PathSet validPaths; | ||||||
|     if (printStatus) { |     if (printStatus) { | ||||||
|         PathSet paths; |         PathSet paths; | ||||||
|         foreach (vector<DrvInfo>::iterator, i, elems2) |         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); |                 printMsg(lvlTalkative, format("skipping derivation named `%1%' which gives an assertion failure") % i->name); | ||||||
|                 i->setFailed(); |                 i->setFailed(); | ||||||
|             } |             } | ||||||
|  |         validPaths = store->queryValidPaths(paths); | ||||||
|         store->querySubstitutablePathInfos(paths, subs); |         store->querySubstitutablePathInfos(paths, subs); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -966,9 +968,10 @@ static void opQuery(Globals & globals, | ||||||
|             XMLAttrs attrs; |             XMLAttrs attrs; | ||||||
| 
 | 
 | ||||||
|             if (printStatus) { |             if (printStatus) { | ||||||
|                 bool hasSubs = subs.find(i->queryOutPath(globals.state)) != subs.end(); |                 Path outPath = i->queryOutPath(globals.state); | ||||||
|                 bool isInstalled = installed.find(i->queryOutPath(globals.state)) != installed.end(); |                 bool hasSubs = subs.find(outPath) != subs.end(); | ||||||
|                 bool isValid = store->isValidPath(i->queryOutPath(globals.state)); |                 bool isInstalled = installed.find(outPath) != installed.end(); | ||||||
|  |                 bool isValid = validPaths.find(outPath) != validPaths.end(); | ||||||
|                 if (xmlOutput) { |                 if (xmlOutput) { | ||||||
|                     attrs["installed"] = isInstalled ? "1" : "0"; |                     attrs["installed"] = isInstalled ? "1" : "0"; | ||||||
|                     attrs["valid"] = isValid ? "1" : "0"; |                     attrs["valid"] = isValid ? "1" : "0"; | ||||||
|  |  | ||||||
|  | @ -297,6 +297,15 @@ static void performOp(unsigned int clientVersion, | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     case wopQueryValidPaths: { | ||||||
|  |         PathSet paths = readStorePaths<PathSet>(from); | ||||||
|  |         startWork(); | ||||||
|  |         PathSet res = store->queryValidPaths(paths); | ||||||
|  |         stopWork(); | ||||||
|  |         writeStrings(res, to); | ||||||
|  |         break; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     case wopHasSubstitutes: { |     case wopHasSubstitutes: { | ||||||
|         Path path = readStorePath(from); |         Path path = readStorePath(from); | ||||||
|         startWork(); |         startWork(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue