mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-31 15:56:25 +08:00
Optimize GetConnectionScope performance
This commit is contained in:
parent
cbaf34343d
commit
3e04f60536
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user