Skip to content

Commit a5bd6fd

Browse files
author
Kapil Borle
committed
Change SaveModule implementation
Previously, SaveModule method in ModuleDependency handler would invoke Find-Module and then Save-Module. This is inefficient as two queries are made the PSGallery server which are redundant. This commit removes Find-Module invocation.
1 parent ddae10f commit a5bd6fd

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

Engine/Generic/ModuleDependencyHandler.cs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,6 @@ public PSObject FindModule(string moduleName)
239239
return module;
240240
}
241241

242-
243-
public bool ModuleExists(string moduleName)
244-
{
245-
throw new NotImplementedException();
246-
}
247-
248242
public bool TrySaveModule(string moduleName)
249243
{
250244
try
@@ -259,9 +253,6 @@ public bool TrySaveModule(string moduleName)
259253
}
260254
}
261255

262-
// TODO Do not use find module because it leads to two queries to the server
263-
// instead use save module and check if it couldn't find the module
264-
// TODO Add a TrySaveModule method
265256
public void SaveModule(string moduleName)
266257
{
267258
ThrowIfNull(moduleName, "moduleName");
@@ -270,16 +261,12 @@ public void SaveModule(string moduleName)
270261
return;
271262
}
272263

273-
var module = FindModule(moduleName);
274-
if (module == null)
275-
{
276-
throw new ItemNotFoundException(
277-
string.Format(
278-
"Cannot find {0} in {1} repository.",
279-
moduleName,
280-
moduleRepository));
281-
}
282-
SaveModule(module);
264+
var ps = System.Management.Automation.PowerShell.Create();
265+
ps.Runspace = runspace;
266+
ps.AddCommand("Save-Module")
267+
.AddParameter("Path", tempDirPath)
268+
.AddParameter("Name", moduleName);
269+
ps.Invoke();
283270
AddModuleName(modulesSavedInTempPath, moduleName);
284271
}
285272

0 commit comments

Comments
 (0)