Skip to content

Commit a2b9b42

Browse files
author
Kapil Borle
committed
Initialize command info cache
1 parent b660cc3 commit a2b9b42

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Engine/Helper.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,27 @@ public void Initialize()
156156
runspacePool.SetMaxRunspaces(3);
157157
runspacePool.Open();
158158

159-
IEnumerable<CommandInfo> aliases = this.invokeCommand.GetCommands("*", CommandTypes.Alias, true);
159+
// set up command info cache
160+
foreach (var cmdInfo in this.invokeCommand.GetCommands("*", CommandTypes.All, true))
161+
{
162+
if (!commandInfoCache.ContainsKey(cmdInfo.Name))
163+
{
164+
commandInfoCache.AddOrUpdate(cmdInfo.Name, key => cmdInfo, (key, value) => cmdInfo);
165+
}
166+
else
167+
{
168+
var version = commandInfoCache[cmdInfo.Name].Version;
169+
if (cmdInfo.Version != null
170+
&& (version == null
171+
|| cmdInfo.Version > commandInfoCache[cmdInfo.Name].Version))
172+
{
173+
commandInfoCache[cmdInfo.Name] = cmdInfo;
174+
}
175+
}
176+
}
160177

161-
foreach (AliasInfo aliasInfo in aliases)
178+
// set up alias cache
179+
foreach (AliasInfo aliasInfo in commandInfoCache.Values.Where(cmdInfo => cmdInfo.CommandType == CommandTypes.Alias))
162180
{
163181
if (!CmdletToAliasDictionary.ContainsKey(aliasInfo.Definition))
164182
{

0 commit comments

Comments
 (0)