Optimized Code

This commit is contained in:
sunkaixuna 2021-12-16 01:15:16 +08:00
parent 94a8c30bd6
commit fca2a2d59d

View File

@ -646,6 +646,8 @@ namespace SqlSugar
{
return ScopedContext.Fastest<T>();
}
private SqlSugarClient GetContext()
{
SqlSugarClient result = null;
@ -669,7 +671,8 @@ namespace SqlSugar
SqlSugarClient result = CallContextAsync<SqlSugarClient>.GetData(key);
if (result == null)
{
CallContextAsync<SqlSugarClient>.SetData(key, new SqlSugarClient(_configs));
List<ConnectionConfig> configList = GetCopyConfigs();
CallContextAsync<SqlSugarClient>.SetData(key, new SqlSugarClient(configList));
result = CallContextAsync<SqlSugarClient>.GetData(key);
if (this._configAction != null)
{
@ -685,7 +688,21 @@ namespace SqlSugar
SqlSugarClient result = CallContextThread<SqlSugarClient>.GetData(key);
if (result == null)
{
CallContextThread<SqlSugarClient>.SetData(key, new SqlSugarClient(_configs.Select(it=>new ConnectionConfig() {
List<ConnectionConfig> configList = GetCopyConfigs();
CallContextThread<SqlSugarClient>.SetData(key, new SqlSugarClient(configList));
result = CallContextThread<SqlSugarClient>.GetData(key);
if (this._configAction != null)
{
this._configAction(result);
}
}
return result;
}
private List<ConnectionConfig> GetCopyConfigs()
{
return _configs.Select(it => new ConnectionConfig()
{
AopEvents = it.AopEvents,
ConfigId = it.ConfigId,
ConfigureExternalServices = it.ConfigureExternalServices,
@ -695,7 +712,8 @@ namespace SqlSugar
InitKeyType = it.InitKeyType,
IsAutoCloseConnection = it.IsAutoCloseConnection,
LanguageType = it.LanguageType,
MoreSettings=it.MoreSettings==null?null:new ConnMoreSettings() {
MoreSettings = it.MoreSettings == null ? null : new ConnMoreSettings()
{
DefaultCacheDurationInSeconds = it.MoreSettings.DefaultCacheDurationInSeconds,
DisableNvarchar = it.MoreSettings.DisableNvarchar,
PgSqlIsAutoToLower = it.MoreSettings.PgSqlIsAutoToLower,
@ -703,14 +721,7 @@ namespace SqlSugar
IsWithNoLockQuery = it.MoreSettings.IsWithNoLockQuery
},
SlaveConnectionConfigs = it.SlaveConnectionConfigs
}).ToList()));
result = CallContextThread<SqlSugarClient>.GetData(key);
if (this._configAction != null)
{
this._configAction(result);
}
}
return result;
}).ToList();
}
}
}