I have two tables, inputs and outputs. The output table contains a column "connected inputs" which contains PKs from the input table.
I want to get all the display keys for outputs connected to a few selected inputs (also based on display keys). At the moment I need to get all the table display keys from from the input table, filter based on the display keys I want, then FindPrimaryKey for those rows. Then I get all the display keys for the output table and since we can't fetch an entire table or a column which isn't PK or DK column I need to do GetParameter on each row in the output table (1700+ rows) to get the Connected Input for each output which is taking a looong time so that I can then filter the outputs to the ones using a specific input.
This is a script that runs when opening the visual overview; right now it takes 20+ seconds to load the visual overview since the script blocks the screen until finished. Is there a way to speed this up?
var prefix = (string) engine.GetScriptParam("Prefix").Value;
var dummy = engine.GetDummy("dummy");// inputs we want
string[] sourceKeys = dummy.GetTableDisplayKeys(1400)
.Where(dk => dk.StartsWith(prefix + " AUX "))
.OrderBy(dk => dk)
.Select(dk => dummy.FindPrimaryKey(1400, dk))
.ToArray<string>();// populate dict to speed up filtering
var destinations = new Dictionary<string, List<string>>();foreach(var dk in dummy.GetTableDisplayKeys(1500))
{
var connectedInput = (string) dummy.GetParameter(1506, dk);
if (!String.IsNullOrEmpty(connectedInput) && Array.Exists(sourceKeys, key => key.Equals(connectedInput))) {
if(!destinations.ContainsKey(connectedInput))
destinations[connectedInput] = new List<string>();
destinations[connectedInput].Add(dk);
}
}// return outputs connected to each input
for(var i = 0; i< sourceKeys.Length; i++)
{
if (destinations.ContainsKey(sourceKeys[i]))
engine.AddScriptOutput(UIVariables.VisualOverview.CreateKey($"Aux{i+1}"), string.Join(", ", destinations[sourceKeys[i]]));
}