Skip to content

Commit

Permalink
Performance(csi) : commit database tables in single transaction (spec…
Browse files Browse the repository at this point in the history
…klesystems#2998)

* add way to commit database tables in single transaction

* relocate csiSharedResources

* Create IFinalizable interface in core

* remove project from sln as well as slnf

---------

Co-authored-by: Connor Ivy <[email protected]>
Co-authored-by: Alan Rynne <[email protected]>
  • Loading branch information
3 people authored Nov 7, 2023
1 parent 61412a5 commit 7192a2b
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 106 deletions.
64 changes: 32 additions & 32 deletions All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2065,38 +2065,6 @@ Global
{737D5567-7B1F-410D-9B7B-BAE8065ED15B}.Release|Any CPU.Build.0 = Release|Any CPU
{737D5567-7B1F-410D-9B7B-BAE8065ED15B}.Release|x64.ActiveCfg = Release|Any CPU
{737D5567-7B1F-410D-9B7B-BAE8065ED15B}.Release|x64.Build.0 = Release|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug Mac|x64.ActiveCfg = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug Mac|x64.Build.0 = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug|x64.ActiveCfg = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug|x64.Build.0 = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release Mac|Any CPU.ActiveCfg = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release Mac|Any CPU.Build.0 = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release Mac|x64.ActiveCfg = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release Mac|x64.Build.0 = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release|Any CPU.Build.0 = Release|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release|x64.ActiveCfg = Release|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release|x64.Build.0 = Release|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug Mac|x64.ActiveCfg = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug Mac|x64.Build.0 = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug|x64.ActiveCfg = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug|x64.Build.0 = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release Mac|Any CPU.ActiveCfg = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release Mac|Any CPU.Build.0 = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release Mac|x64.ActiveCfg = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release Mac|x64.Build.0 = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release|Any CPU.Build.0 = Release|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release|x64.ActiveCfg = Release|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release|x64.Build.0 = Release|Any CPU
{75144587-6F51-46C8-8E40-DA652FBC53F4}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU
{75144587-6F51-46C8-8E40-DA652FBC53F4}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU
{75144587-6F51-46C8-8E40-DA652FBC53F4}.Debug Mac|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -2145,6 +2113,38 @@ Global
{A0C9EBE0-A56A-4D07-B6EF-2EEAEC45D6C4}.Release|Any CPU.Build.0 = Release|Any CPU
{A0C9EBE0-A56A-4D07-B6EF-2EEAEC45D6C4}.Release|x64.ActiveCfg = Release|Any CPU
{A0C9EBE0-A56A-4D07-B6EF-2EEAEC45D6C4}.Release|x64.Build.0 = Release|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug Mac|x64.ActiveCfg = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug Mac|x64.Build.0 = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug|x64.ActiveCfg = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Debug|x64.Build.0 = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release Mac|Any CPU.ActiveCfg = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release Mac|Any CPU.Build.0 = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release Mac|x64.ActiveCfg = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release Mac|x64.Build.0 = Debug|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release|Any CPU.Build.0 = Release|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release|x64.ActiveCfg = Release|Any CPU
{7F0206A9-61D4-4D3A-9B43-789DABA7C143}.Release|x64.Build.0 = Release|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug Mac|x64.ActiveCfg = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug Mac|x64.Build.0 = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug|x64.ActiveCfg = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Debug|x64.Build.0 = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release Mac|Any CPU.ActiveCfg = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release Mac|Any CPU.Build.0 = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release Mac|x64.ActiveCfg = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release Mac|x64.Build.0 = Debug|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release|Any CPU.Build.0 = Release|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release|x64.ActiveCfg = Release|Any CPU
{2CC777EB-BD63-4FAB-BC3A-68A640D2E639}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion ConnectorCSI/ConnectorCSIBridge/ConnectorCSIBridge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DriverPluginCSharp\DriverPluginCSharp.csproj"/>
<ProjectReference Include="..\DriverPluginCSharp\DriverPluginCSharp.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ConnectorCSI.Storage;
using ConnectorCSI.Storage;
using DesktopUI2;
using DesktopUI2.Models;
using DesktopUI2.ViewModels;
Expand All @@ -18,6 +18,8 @@
using Serilog.Context;
using Speckle.Core.Logging;
using Speckle.Core.Models.GraphTraversal;
using Speckle.Core.Logging;
using Speckle.Core.Kits.ConverterInterfaces;

namespace Speckle.ConnectorCSI.UI
{
Expand All @@ -38,7 +40,7 @@ public override async Task<StreamState> ReceiveStream(StreamState state, Progres

var kit = KitManager.GetDefaultKit();
var appName = GetHostAppVersion(Model);
var converter = kit.LoadConverter(appName);
ISpeckleConverter converter = kit.LoadConverter(appName);

// set converter settings as tuples (setting slug, setting selection)
// for csi, these must go before the SetContextDocument method.
Expand Down Expand Up @@ -151,6 +153,11 @@ private List<ApplicationObject> ConvertReceivedObjects(ISpeckleConverter convert
progress.Update(conversionProgressDict);
}

if (converter is IFinalizable finalizable)
{
finalizable.FinalizeConversion();
}

return conversionResults;
}

Expand Down
2 changes: 1 addition & 1 deletion ConnectorCSI/ConnectorSAP2000/ConnectorSAP2000.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DriverPluginCSharp\DriverPluginCSharp.csproj"/>
<ProjectReference Include="..\DriverPluginCSharp\DriverPluginCSharp.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion ConnectorCSI/DriverCSharp/DriverCSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<Copyright />
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<Import Project="..\ConnectorCSIShared\ConnectorCSIShared.projitems" Label="Shared" />
<ItemGroup>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -23,4 +22,5 @@
<ItemGroup>
<PackageReference Include="CSiAPIv1" Version="1.0.0" />
</ItemGroup>
<Import Project="..\ConnectorCSIShared\ConnectorCSIShared.projitems" Label="Shared" />
</Project>
7 changes: 7 additions & 0 deletions Core/Core/Kits/ConverterInterfaces/IFinalizable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Speckle.Core.Kits.ConverterInterfaces
{
public interface IFinalizable
{
void FinalizeConversion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSiAPIv1" Version="1.0.0"/>
<PackageReference Include="CSiAPIv1" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\Core\Core\Core.csproj"/>
<ProjectReference Include="..\..\..\Objects\Objects.csproj"/>
<ProjectReference Include="..\..\StructuralUtilities\PolygonMesher\PolygonMesher.csproj"/>
<ProjectReference Include="..\..\..\..\Core\Core\Core.csproj" />
<ProjectReference Include="..\..\..\Objects\Objects.csproj" />
<ProjectReference Include="..\..\StructuralUtilities\PolygonMesher\PolygonMesher.csproj" />
</ItemGroup>

<ItemGroup>
Expand All @@ -33,12 +33,10 @@
</Reference>
</ItemGroup>

<Target Name="CopyDependenciesToKitfolder" AfterTargets="CopyToKitFolder"
Condition="'$(IsDesktopBuild)' == true">
<Message Text="Copying dependencies to kit folder"/>
<Exec Condition="$([MSBuild]::IsOsPlatform('Windows'))"
Command="xcopy /Y /S &quot;$(TargetDir)PolygonMesher.dll&quot; &quot;$(AppData)\Speckle\Kits\Objects\&quot;"/>
<Target Name="CopyDependenciesToKitfolder" AfterTargets="CopyToKitFolder" Condition="'$(IsDesktopBuild)' == true">
<Message Text="Copying dependencies to kit folder" />
<Exec Condition="$([MSBuild]::IsOsPlatform('Windows'))" Command="xcopy /Y /S &quot;$(TargetDir)PolygonMesher.dll&quot; &quot;$(AppData)\Speckle\Kits\Objects\&quot;" />
</Target>

<Import Project="..\ConverterCSIShared\ConverterCSIShared.projitems" Label="Shared"/>
<Import Project="..\ConverterCSIShared\ConverterCSIShared.projitems" Label="Shared" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using ConverterCSIShared.Models;

namespace Objects.Converter.CSI
{
public partial class ConverterCSI
{
private ETABSGridLineDefinitionTable gridLineDefinitionTable;
private ETABSGridLineDefinitionTable GridLineDefinitionTable => gridLineDefinitionTable ??= new(Model, new(Model));
public void CommitAllDatabaseTableChanges()
{
GridLineDefinitionTable.CommitPendingChanges();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
using Objects.Other;
using Objects.Structural.Materials;
using OSG = Objects.Structural.Geometry;
using Speckle.Core.Kits.ConverterInterfaces;

namespace Objects.Converter.CSI
{
public partial class ConverterCSI : ISpeckleConverter
public partial class ConverterCSI : ISpeckleConverter, IFinalizable
{
#if ETABS
public static string CSIAppName = HostApplications.ETABS.Name;
Expand Down Expand Up @@ -432,5 +433,10 @@ public List<Base> ConvertToSpeckle(List<object> objects)
}

public IEnumerable<string> GetServicedApplications() => new string[] { CSIAppName };

public void FinalizeConversion()
{
CommitAllDatabaseTableChanges();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)ConverterCSI.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ConverterCSIUtils.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ConverterCSI.DatabaseTableUtils.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ArcExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\CurveExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ICurveExtensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@
using System.Collections.Generic;
using ConverterCSIShared.Services;
using CSiAPIv1;
using Speckle.Core.Logging;

namespace ConverterCSIShared.Models
{
internal abstract class DatabaseTableWrapper
{
public abstract string TableKey { get; }

protected readonly cSapModel cSapModel;
protected readonly ToNativeScalingService toNativeScalingService;

private int tableVersion;
protected string[] fieldKeysIncluded;
protected int numRecords;
private readonly List<string> tableData;
private int numRecords;
private List<string> tableData;

private readonly List<string[]> rowsToAdd = new();
protected DatabaseTableWrapper(cSapModel cSapModel, ToNativeScalingService toNativeScalingService)
{
this.cSapModel = cSapModel;
this.toNativeScalingService = toNativeScalingService;
this.tableData = new List<string>(GetTableData());
RefreshTableData();
}

private string[] GetTableData()
private void RefreshTableData()
{
var tableData = Array.Empty<string>();
cSapModel.DatabaseTables.GetTableForEditingArray(
Expand All @@ -33,22 +36,29 @@ private string[] GetTableData()
ref numRecords,
ref tableData
);
return tableData;
this.tableData = new List<string>(tableData);
}

protected void AddRow(params string[] arguments)
protected void AddRowToBeCommitted(params string[] arguments)
{
if (arguments.Length != fieldKeysIncluded.Length)
{
throw new ArgumentException(
$"Method {nameof(AddRow)} was passed an array of length {arguments.Length}, but was expecting an array of length {fieldKeysIncluded.Length}"
);
throw new ArgumentException($"Method {nameof(AddRowToBeCommitted)} was passed an array of length {arguments.Length}, but was expecting an array of length {fieldKeysIncluded.Length}");
}
rowsToAdd.Add(arguments);
}

public void CommitPendingChanges()
{
foreach (string[] row in rowsToAdd)
{
tableData.AddRange(row);
numRecords++;
}
tableData.AddRange(arguments);
numRecords++;
ApplyTablesEditedTables();
}

public void ApplyEditedTables()
private void ApplyTablesEditedTables()
{
var tableDataArray = tableData.ToArray();
cSapModel.DatabaseTables.SetTableForEditingArray(
Expand All @@ -64,14 +74,13 @@ ref tableDataArray
int numInfoMsgs = 0;
int numErrorMsgs = 0;
string importLog = "";
cSapModel.DatabaseTables.ApplyEditedTables(
false,
ref numFatalErrors,
ref numErrorMsgs,
ref numWarnMsgs,
ref numInfoMsgs,
ref importLog
);
cSapModel.DatabaseTables.ApplyEditedTables(false, ref numFatalErrors, ref numErrorMsgs, ref numWarnMsgs, ref numInfoMsgs, ref importLog);

if (numFatalErrors == 0 && numErrorMsgs == 0)
{
SpeckleLog.Logger.Error("{numErrors} errors and {numFatalErrors} fatal errors occurred when attempting to add {numRowsToAdd} rows to table with key, {tableKey}", numErrorMsgs, numFatalErrors, rowsToAdd.Count, TableKey);
}
rowsToAdd.Clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void AddCartesian(
};
}

AddRow(newRow);
AddRowToBeCommitted(newRow);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
using System;
using System.Collections.Generic;
using Objects.Geometry;
using Objects.Structural.CSI.Geometry;
using Objects.BuiltElements;
using ConverterCSIShared.Models;

namespace Objects.Converter.CSI
{
public partial class ConverterCSI
{
private ETABSGridLineDefinitionTable gridLineDefinitionTable;
private ETABSGridLineDefinitionTable GridLineDefinitionTable => gridLineDefinitionTable ??= new(Model, new(Model));

public void GridLineToNative(GridLine gridline)
{
GridLineDefinitionTable.AddCartesian(gridline);
GridLineDefinitionTable.ApplyEditedTables();
}

public CSIGridLines gridLinesToSpeckle(string name)
Expand Down
Loading

0 comments on commit 7192a2b

Please sign in to comment.