Skip to content

Commit 1ec297e

Browse files
authored
improving OE tables expand (#555)
* improving OE tables expand for dw database
1 parent ab332cb commit 1ec297e

File tree

11 files changed

+84
-43
lines changed

11 files changed

+84
-43
lines changed

src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/ChildFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public abstract class ChildFactory
4545
/// <summary>
4646
/// Returns the node sub type if the object can have sub types otehr wise returns empty string
4747
/// </summary>
48-
public abstract string GetNodeSubType(object context);
48+
public abstract string GetNodeSubType(object smoObject, SmoQueryContext smoContext);
4949

5050
/// <summary>
5151
/// Returns the status of the object assigned to node. If the object doesn't spport status returns empty string
5252
/// </summary>
53-
public abstract string GetNodeStatus(object context);
53+
public abstract string GetNodeStatus(object smoObject, SmoQueryContext smoContext);
5454

5555
/// <summary>
5656
/// Returns the custom name of the object assigned to the node. If the object doesn't have custom name, returns empty string

src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeObservableCollection.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6+
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
67
using System;
78
using System.Collections.Generic;
89
using System.Collections.ObjectModel;
@@ -29,6 +30,15 @@ public bool IsPopulating
2930
get { return numInits.HasValue && numInits != 0; }
3031
}
3132

33+
public bool IsSorted
34+
{
35+
get
36+
{
37+
// SMO objects are already sorted so no need to sort them again
38+
return this.FirstOrDefault() is SmoTreeNode;
39+
}
40+
}
41+
3242
public void BeginInit()
3343
{
3444
if (!numInits.HasValue)
@@ -54,7 +64,10 @@ public void EndInit(TreeNode parent, ref IList<TreeNode> deferredChildren)
5464
{
5565
try
5666
{
57-
DoSort();
67+
if (!IsSorted)
68+
{
69+
DoSort();
70+
}
5871

5972
if (deferredChildren != null)
6073
{

src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
1717
{
1818
public class SmoChildFactoryBase : ChildFactory
1919
{
20+
private IEnumerable<NodeSmoProperty> smoProperties;
2021
public override IEnumerable<string> ApplicableParents()
2122
{
2223
return null;
@@ -230,6 +231,7 @@ protected virtual void InitializeChild(TreeNode parent, TreeNode child, object c
230231
}
231232
else
232233
{
234+
smoProperties = SmoProperties;
233235
SmoTreeNode childAsMeItem = (SmoTreeNode)child;
234236
childAsMeItem.CacheInfoFromModel(smoObj);
235237
SmoQueryContext smoContext = parent.GetContextAs<SmoQueryContext>();
@@ -241,8 +243,8 @@ protected virtual void InitializeChild(TreeNode parent, TreeNode child, object c
241243
childAsMeItem.NodeValue = customizedName;
242244
}
243245

244-
childAsMeItem.NodeSubType = GetNodeSubType(context);
245-
childAsMeItem.NodeStatus = GetNodeStatus(context);
246+
childAsMeItem.NodeSubType = GetNodeSubType(context, smoContext);
247+
childAsMeItem.NodeStatus = GetNodeStatus(context, smoContext);
246248
}
247249
}
248250

@@ -270,6 +272,14 @@ public override IEnumerable<NodeSmoProperty> SmoProperties
270272
}
271273
}
272274

275+
internal IEnumerable<NodeSmoProperty> CachedSmoProperties
276+
{
277+
get
278+
{
279+
return smoProperties == null ? SmoProperties : smoProperties;
280+
}
281+
}
282+
273283
/// <summary>
274284
/// Returns true if any final validation of the object to be added passes, and false
275285
/// if validation fails. This provides a chance to filter specific items out of a list
@@ -282,16 +292,31 @@ public virtual bool PassesFinalFilters(TreeNode parent, object context)
282292
return true;
283293
}
284294

285-
public override string GetNodeSubType(object context)
295+
public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
286296
{
287297
return string.Empty;
288298
}
289299

290-
public override string GetNodeStatus(object context)
300+
public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
291301
{
292302
return string.Empty;
293303
}
294304

305+
public static bool IsPropertySupported(string propertyName, SmoQueryContext context, NamedSmoObject smoObj, IEnumerable<NodeSmoProperty> supportedProperties)
306+
{
307+
var property = supportedProperties.FirstOrDefault(x => string.Compare(x.Name, propertyName, StringComparison.InvariantCultureIgnoreCase) == 0);
308+
if (property != null)
309+
{
310+
return ServerVersionHelper.IsValidFor(context.ValidFor, property.ValidFor);
311+
}
312+
else
313+
{
314+
// Return true if cannot find the proeprty, SMO still tries to get that property but adding the property to supported list can make loading the nodes faster
315+
Logger.Write(LogLevel.Verbose, $"Smo property name {propertyName} for Smo type {smoObj.GetType()} is not added as supported properties. This can cause the performance of loading the OE nodes");
316+
return true;
317+
}
318+
}
319+
295320
public override string GetNodeCustomName(object smoObject, SmoQueryContext smoContext)
296321
{
297322
return string.Empty;

src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoDatabaseCustomNode.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//
55

66
using Microsoft.SqlServer.Management.Smo;
7+
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
8+
using System.Collections.Generic;
79

810
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
911
{
@@ -12,21 +14,22 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
1214
/// </summary>
1315
internal partial class DatabasesChildFactory : SmoChildFactoryBase
1416
{
15-
public override string GetNodeStatus(object context)
17+
public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
1618
{
17-
return DatabasesCustomNodeHelper.GetStatus(context);
19+
return DatabasesCustomNodeHelper.GetStatus(smoObject, smoContext, CachedSmoProperties);
1820
}
1921
}
2022

2123
internal static class DatabasesCustomNodeHelper
2224
{
23-
internal static string GetStatus(object context)
25+
internal static string GetStatus(object smoObject, SmoQueryContext smoContext, IEnumerable<NodeSmoProperty> supportedProperties)
2426
{
25-
Database db = context as Database;
26-
if (db != null)
27+
Database db = smoObject as Database;
28+
if (db != null && SmoChildFactoryBase.IsPropertySupported("Status", smoContext, db, supportedProperties))
2729
{
2830
DatabaseStatus status;
29-
try {
31+
try
32+
{
3033
status = db.Status;
3134
}
3235
catch (SqlServer.Management.Common.ConnectionFailureException)

src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoKeyCustomNode.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
1212
/// </summary>
1313
internal partial class KeysChildFactory : SmoChildFactoryBase
1414
{
15-
public override string GetNodeSubType(object context)
15+
public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
1616
{
17-
return IndexCustomeNodeHelper.GetSubType(context);
17+
return IndexCustomeNodeHelper.GetSubType(smoObject);
1818
}
1919
}
2020

@@ -23,9 +23,9 @@ public override string GetNodeSubType(object context)
2323
/// </summary>
2424
internal partial class IndexesChildFactory : SmoChildFactoryBase
2525
{
26-
public override string GetNodeSubType(object context)
26+
public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
2727
{
28-
return IndexCustomeNodeHelper.GetSubType(context);
28+
return IndexCustomeNodeHelper.GetSubType(smoObject);
2929
}
3030

3131
public override string GetNodeCustomName(object smoObject, SmoQueryContext smoContext)
@@ -39,9 +39,9 @@ public override string GetNodeCustomName(object smoObject, SmoQueryContext smoCo
3939
/// </summary>
4040
internal partial class UserDefinedTableTypeKeysChildFactory : SmoChildFactoryBase
4141
{
42-
public override string GetNodeSubType(object context)
42+
public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
4343
{
44-
return IndexCustomeNodeHelper.GetSubType(context);
44+
return IndexCustomeNodeHelper.GetSubType(smoObject);
4545
}
4646
}
4747

src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoLoginCustomNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
1212
/// </summary>
1313
internal partial class ServerLevelLoginsChildFactory : SmoChildFactoryBase
1414
{
15-
public override string GetNodeStatus(object context)
15+
public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
1616
{
17-
return LoginCustomNodeHelper.GetStatus(context);
17+
return LoginCustomNodeHelper.GetStatus(smoObject);
1818
}
1919
}
2020

src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoParamterCustomNode.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public override string GetNodeCustomName(object smoObject, SmoQueryContext smoCo
1818
return ParameterCustomeNodeHelper.GetCustomLabel(smoObject, smoContext);
1919
}
2020

21-
public override string GetNodeSubType(object context)
21+
public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
2222
{
23-
return ParameterCustomeNodeHelper.GetSubType(context);
23+
return ParameterCustomeNodeHelper.GetSubType(smoObject);
2424
}
2525
}
2626

@@ -33,9 +33,9 @@ public override string GetNodeCustomName(object smoObject, SmoQueryContext smoCo
3333
{
3434
return ParameterCustomeNodeHelper.GetCustomLabel(smoObject, smoContext);
3535
}
36-
public override string GetNodeSubType(object context)
36+
public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
3737
{
38-
return ParameterCustomeNodeHelper.GetSubType(context);
38+
return ParameterCustomeNodeHelper.GetSubType(smoObject);
3939
}
4040
}
4141

@@ -48,9 +48,9 @@ public override string GetNodeCustomName(object smoObject, SmoQueryContext smoCo
4848
{
4949
return ParameterCustomeNodeHelper.GetCustomLabel(smoObject, smoContext);
5050
}
51-
public override string GetNodeSubType(object context)
51+
public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
5252
{
53-
return ParameterCustomeNodeHelper.GetSubType(context);
53+
return ParameterCustomeNodeHelper.GetSubType(smoObject);
5454
}
5555
}
5656

@@ -63,9 +63,9 @@ public override string GetNodeCustomName(object smoObject, SmoQueryContext smoCo
6363
{
6464
return ParameterCustomeNodeHelper.GetCustomLabel(smoObject, smoContext);
6565
}
66-
public override string GetNodeSubType(object context)
66+
public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
6767
{
68-
return ParameterCustomeNodeHelper.GetSubType(context);
68+
return ParameterCustomeNodeHelper.GetSubType(smoObject);
6969
}
7070
}
7171

src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoTableCustomNode.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public override string GetNodeCustomName(object smoObject, SmoQueryContext smoCo
1717
try
1818
{
1919
Table table = smoObject as Table;
20-
if (table != null && table.IsSystemVersioned)
20+
if (table != null && IsPropertySupported("IsSystemVersioned", smoContext, table, CachedSmoProperties) && table.IsSystemVersioned)
2121
{
2222
return $"{table.Schema}.{table.Name} ({SR.SystemVersioned_LabelPart})";
2323
}
@@ -30,12 +30,12 @@ public override string GetNodeCustomName(object smoObject, SmoQueryContext smoCo
3030
return string.Empty;
3131
}
3232

33-
public override string GetNodeSubType(object context)
33+
public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
3434
{
3535
try
3636
{
37-
Table table = context as Table;
38-
if (table != null && table.TemporalType != TableTemporalType.None)
37+
Table table = smoObject as Table;
38+
if (table != null && IsPropertySupported("TemporalType", smoContext, table, CachedSmoProperties) && table.TemporalType != TableTemporalType.None)
3939
{
4040
return "Temporal";
4141
}

src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoTriggerCustomNode.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
1212
/// </summary>
1313
internal partial class TriggersChildFactory : SmoChildFactoryBase
1414
{
15-
public override string GetNodeStatus(object context)
15+
public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
1616
{
17-
return TriggersCustomeNodeHelper.GetStatus(context);
17+
return TriggersCustomeNodeHelper.GetStatus(smoObject);
1818
}
1919
}
2020

2121
internal partial class ServerLevelServerTriggersChildFactory : SmoChildFactoryBase
2222
{
23-
public override string GetNodeStatus(object context)
23+
public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
2424
{
25-
return TriggersCustomeNodeHelper.GetStatus(context);
25+
return TriggersCustomeNodeHelper.GetStatus(smoObject);
2626
}
2727
}
2828

2929
internal partial class DatabaseTriggersChildFactory : SmoChildFactoryBase
3030
{
31-
public override string GetNodeStatus(object context)
31+
public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
3232
{
33-
return TriggersCustomeNodeHelper.GetStatus(context);
33+
return TriggersCustomeNodeHelper.GetStatus(smoObject);
3434
}
3535
}
3636

src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoUserCustomNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
1212
/// </summary>
1313
internal partial class UsersChildFactory : SmoChildFactoryBase
1414
{
15-
public override string GetNodeStatus(object context)
15+
public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
1616
{
17-
return UserCustomeNodeHelper.GetStatus(context);
17+
return UserCustomeNodeHelper.GetStatus(smoObject);
1818
}
1919
}
2020

0 commit comments

Comments
 (0)