Optimize GetConnectionScope performance

This commit is contained in:
sunkaixuan 2024-03-14 11:54:52 +08:00
parent cbaf34343d
commit 3e04f60536

View File

@ -13,14 +13,24 @@ namespace SqlSugar
public class SqlSugarScopeProvider:ISqlSugarClient
{
internal SqlSugarProvider conn;
internal string InitThreadMainId;
internal string Initkey = null;
StackFrame[] frames;
public SqlSugarScopeProvider(SqlSugarProvider conn)
{
this.conn = conn;
this.InitThreadMainId = GetCurrentThreadId();
var key = GetKey();
this.Initkey = key;
this.GetContext(true);
}
private static string GetCurrentThreadId()
{
return System.Threading.Thread.CurrentThread.ManagedThreadId + "";
}
public SqlSugarProvider ScopedContext { get { return GetContext(); } }
private SqlSugarProvider GetAsyncContext(bool isInit=false)
{
@ -89,6 +99,10 @@ namespace SqlSugar
}
private dynamic GetKey()
{
if (!string.IsNullOrEmpty(this.Initkey) &&this.InitThreadMainId == GetCurrentThreadId())
{
return this.Initkey;
}
var key= "SqlSugarProviderScope_" + conn.CurrentConnectionConfig.ConfigId;
if (frames == null)
{