Performance optimization

This commit is contained in:
sunkaixuan 2023-12-12 20:34:24 +08:00
parent 2f5b819235
commit 279aeb5a5b

View File

@ -113,18 +113,22 @@ namespace SqlSugar
{
identityList = new string[] { };
}
this.Context.Utilities.PageEach(objects, 100, pagelist =>
var pageSize = 100;
var count = inserable.EntityInfo.Columns.Count();
pageSize = GetPageSize(pageSize, count);
this.Context.Utilities.PageEach(objects, pageSize, pagelist =>
{
StringBuilder batchInsetrSql;
List<SugarParameter> allParamter=new List<SugarParameter>();
GetInsertValues(identityList,columns, tableWithString, removeCacheFunc, pagelist, out batchInsetrSql, allParamter);
result += this.Context.Ado.ExecuteCommand(batchInsetrSql.ToString(), allParamter);
StringBuilder batchInsetrSql;
List<SugarParameter> allParamter=new List<SugarParameter>();
GetInsertValues(identityList,columns, tableWithString, removeCacheFunc, pagelist, out batchInsetrSql, allParamter);
result += this.Context.Ado.ExecuteCommand(batchInsetrSql.ToString(), allParamter);
});
return result;
}
public async Task<int> ValuesExecuteCommandAsync()
{
int result = 0;
@ -150,6 +154,24 @@ namespace SqlSugar
return result;
}
#region Values Helper
private static int GetPageSize(int pageSize, int count)
{
if (pageSize * count > 2100)
{
pageSize = 50;
}
if (pageSize * count > 2100)
{
pageSize = 20;
}
if (pageSize * count > 2100)
{
pageSize = 10;
}
return pageSize;
}
private void GetInsertValues(string[] identitys, List<string> columns, string tableWithString, Action removeCacheFunc, List<T> items, out StringBuilder batchInsetrSql, List<SugarParameter> allParamter)
{
var itemable = this.Context.Insertable(items);