瀏覽代碼

😁1、优化仓储初始化,提高并发 2、升级Furion v4.9.1.45

zuohuaijun 2 年之前
父節點
當前提交
d31d510963

+ 3 - 3
Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj

@@ -21,9 +21,9 @@
     <PackageReference Include="AspNet.Security.OAuth.Gitee" Version="6.0.15" />
     <PackageReference Include="AspNet.Security.OAuth.Weixin" Version="6.0.15" />
     <PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
-    <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.1.44" />
-    <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.1.44" />
-    <PackageReference Include="Furion.Pure" Version="4.9.1.44" />
+    <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.1.45" />
+    <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.1.45" />
+    <PackageReference Include="Furion.Pure" Version="4.9.1.45" />
     <PackageReference Include="IPTools.China" Version="1.6.0" />
     <PackageReference Include="Lazy.Captcha.Core" Version="2.0.6" />
     <PackageReference Include="Magicodes.IE.Excel" Version="2.7.5.1" />

+ 10 - 8
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarRepository.cs

@@ -10,33 +10,35 @@ namespace Admin.NET.Core;
 /// <typeparam name="T"></typeparam>
 public class SqlSugarRepository<T> : SimpleClient<T> where T : class, new()
 {
-    protected ITenant iTenant = null;
+    protected static ITenant ITenant { get; set; }
+    protected static SqlSugarScopeProvider MasterDb { get; set; }
 
     public SqlSugarRepository()
     {
-        iTenant = App.GetRequiredService<ISqlSugarClient>().AsTenant();
-        base.Context = iTenant.GetConnectionScope(SqlSugarConst.MainConfigId);
+        ITenant ??= App.GetRequiredService<ISqlSugarClient>().AsTenant();
+        MasterDb ??= ITenant.GetConnectionScope(SqlSugarConst.MainConfigId);
+        base.Context = MasterDb;
 
         // 若实体贴有多库特性,则返回指定库连接
         if (typeof(T).IsDefined(typeof(TenantAttribute), false))
         {
-            base.Context = iTenant.GetConnectionScopeWithAttr<T>();
+            base.Context = ITenant.GetConnectionScopeWithAttr<T>();
             return;
         }
 
         // 若实体贴有日志表特性,则返回日志库连接
         if (typeof(T).IsDefined(typeof(LogTableAttribute), false))
         {
-            base.Context = iTenant.IsAnyConnection(SqlSugarConst.LogConfigId)
-                ? iTenant.GetConnectionScope(SqlSugarConst.LogConfigId)
-                : iTenant.GetConnectionScope(SqlSugarConst.MainConfigId);
+            base.Context = ITenant.IsAnyConnection(SqlSugarConst.LogConfigId)
+                ? ITenant.GetConnectionScope(SqlSugarConst.LogConfigId)
+                : ITenant.GetConnectionScope(SqlSugarConst.MainConfigId);
             return;
         }
 
         // 若实体贴有系统表特性,则返回默认库连接
         if (typeof(T).IsDefined(typeof(SysTableAttribute), false))
         {
-            base.Context = iTenant.GetConnectionScope(SqlSugarConst.MainConfigId);
+            base.Context = ITenant.GetConnectionScope(SqlSugarConst.MainConfigId);
             return;
         }