Removes BulkInsertRecordsWithTransaction and changes tests

This commit is contained in:
Shannon
2019-12-19 17:45:28 +11:00
parent 70adb70afd
commit aae5fc0048
2 changed files with 9 additions and 52 deletions

View File

@@ -30,26 +30,6 @@ namespace Umbraco.Core.Persistence
SqlBulkCopyHelper.SqlTransactionResolver = dbTran => GetTypedTransaction<SqlTransaction>(dbTran);
}
/// <summary>
/// Bulk-inserts records within a transaction.
/// </summary>
/// <typeparam name="T">The type of the records.</typeparam>
/// <param name="database">The database.</param>
/// <param name="records">The records.</param>
/// <param name="useNativeBulkInsert">Whether to use native bulk insert when available.</param>
public static void BulkInsertRecordsWithTransaction<T>(this IUmbracoDatabase database, IEnumerable<T> records, bool useNativeBulkInsert = true)
{
var recordsA = records.ToArray();
if (recordsA.Length == 0)
return;
// no need to "try...catch", if the transaction is not completed it will rollback!
using (var tr = database.GetTransaction())
{
database.BulkInsertRecords(recordsA, useNativeBulkInsert);
tr.Complete();
}
}
/// <summary>
/// Creates bulk-insert commands.

View File

@@ -29,11 +29,9 @@ namespace Umbraco.Tests.Services
[TestFixture]
[Apartment(ApartmentState.STA)]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
[NUnit.Framework.Ignore("These should not be run by the server, only directly as they are only benchmark tests")]
[NUnit.Framework.Explicit("These should not be run by the server, only directly as they are only benchmark tests")]
public class PerformanceTests : TestWithDatabaseBase
{
// FIXME: probably making little sense in places due to scope creating a transaction?!
protected override string GetDbConnectionString()
{
return @"server=.\SQLEXPRESS;database=UmbTest;user id=sa;password=test";
@@ -160,24 +158,6 @@ namespace Umbraco.Tests.Services
scope.Complete();
}
//now, test truncating but then do bulk insertion of records
using (proflog.DebugDuration<PerformanceTests>("Starting truncate + bulk insert test"))
using (var scope = ScopeProvider.CreateScope())
{
//do this 10x!
for (var i = 0; i < 10; i++)
{
//clear all the xml entries
scope.Database.Execute(@"DELETE FROM cmsContentXml WHERE nodeId IN
(SELECT DISTINCT cmsContentXml.nodeId FROM cmsContentXml
INNER JOIN cmsContent ON cmsContentXml.nodeId = cmsContent.nodeId)");
//now we insert each record for the ones we've deleted like we do in the content service.
var xmlItems = nodes.Select(node => new ContentXmlDto { NodeId = node.NodeId, Xml = UpdatedXmlStructure }).ToList();
scope.Database.BulkInsertRecordsWithTransaction(xmlItems);
}
}
//now, test truncating but then do bulk insertion of records
using (proflog.DebugDuration<PerformanceTests>("Starting truncate + bulk insert test in one transaction"))
using (var scope = ScopeProvider.CreateScope())
@@ -188,19 +168,16 @@ namespace Umbraco.Tests.Services
//now we insert each record for the ones we've deleted like we do in the content service.
var xmlItems = nodes.Select(node => new ContentXmlDto { NodeId = node.NodeId, Xml = UpdatedXmlStructure }).ToList();
using (var tr = scope.Database.GetTransaction())
{
//clear all the xml entries
scope.Database.Execute(@"DELETE FROM cmsContentXml WHERE nodeId IN
//clear all the xml entries
scope.Database.Execute(@"DELETE FROM cmsContentXml WHERE nodeId IN
(SELECT DISTINCT cmsContentXml.nodeId FROM cmsContentXml
INNER JOIN cmsContent ON cmsContentXml.nodeId = cmsContent.nodeId)");
scope.Database.BulkInsertRecords(xmlItems);
tr.Complete();
}
scope.Database.BulkInsertRecords(xmlItems);
}
scope.Complete();
}
}
@@ -267,7 +244,7 @@ namespace Umbraco.Tests.Services
using (var scope = ScopeProvider.CreateScope())
{
scope.Database.BulkInsertRecordsWithTransaction(nodes);
scope.Database.BulkInsertRecords(nodes);
//re-get the nodes with ids
var sql = Current.SqlContext.Sql();
@@ -277,11 +254,11 @@ namespace Umbraco.Tests.Services
//create the cmsContent data, each with a new content type id (so we can query on it later if needed)
var contentTypeId = 0;
var cmsContentItems = nodes.Select(node => new ContentDto { NodeId = node.NodeId, ContentTypeId = contentTypeId++ }).ToList();
scope.Database.BulkInsertRecordsWithTransaction(cmsContentItems);
scope.Database.BulkInsertRecords(cmsContentItems);
//create the xml data
var xmlItems = nodes.Select(node => new ContentXmlDto { NodeId = node.NodeId, Xml = TestXmlStructure }).ToList();
scope.Database.BulkInsertRecordsWithTransaction(xmlItems);
scope.Database.BulkInsertRecords(xmlItems);
scope.Complete();
}