😎1、升级依赖 2、调整种子生成(采用StorageableByObject插入或更新,AsUpdateable和AsInsertable 只要执行会导致内存暴涨😂

This commit is contained in:
zuohuaijun 2025-09-16 14:05:47 +08:00
parent b641652d62
commit 1f06ffc4b0
5 changed files with 17 additions and 20 deletions

View File

@ -28,9 +28,9 @@
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" /> <PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" Aliases="BouncyCastleV2" /> <PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" Aliases="BouncyCastleV2" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="9.1.7" /> <PackageReference Include="Elastic.Clients.Elasticsearch" Version="9.1.7" />
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.7.121" /> <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.7.123" />
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.7.121" /> <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.7.123" />
<PackageReference Include="Furion.Pure" Version="4.9.7.121" /> <PackageReference Include="Furion.Pure" Version="4.9.7.123" />
<PackageReference Include="Hardware.Info" Version="101.0.1.1" /> <PackageReference Include="Hardware.Info" Version="101.0.1.1" />
<PackageReference Include="Hashids.net" Version="1.7.0" /> <PackageReference Include="Hashids.net" Version="1.7.0" />
<PackageReference Include="IPTools.China" Version="1.6.0" /> <PackageReference Include="IPTools.China" Version="1.6.0" />

View File

@ -4,7 +4,6 @@
// //
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using NewLife.IO;
using NewLife.Reflection; using NewLife.Reflection;
using System.Text.Json; using System.Text.Json;
@ -437,7 +436,7 @@ public static class SqlSugarExtension
if (handleBefore != null) foreach (var sd in seedData) handleBefore(sd); if (handleBefore != null) foreach (var sd in seedData) handleBefore(sd);
dbProvider.QueryFilter.ClearAndBackup(); dbProvider.QueryFilter.ClearAndBackup();
int total, insertCount = 0, updateCount = 0; int total = 0, insertCount = 0, updateCount = 0;
if (entityType.GetCustomAttribute<SplitTableAttribute>(true) != null) if (entityType.GetCustomAttribute<SplitTableAttribute>(true) != null)
{ {
// 拆分表的操作需要实体类型,而通过反射很难实现 // 拆分表的操作需要实体类型,而通过反射很难实现
@ -457,13 +456,10 @@ public static class SqlSugarExtension
// 按主键进行批量增加和更新 // 按主键进行批量增加和更新
if (entityInfo.Columns.Any(u => u.IsPrimarykey)) if (entityInfo.Columns.Any(u => u.IsPrimarykey))
{ {
// 先修改再插入,否则会更新修改时间字段
var storage = dbProvider.StorageableByObject(seedDataList).ToStorage(); var storage = dbProvider.StorageableByObject(seedDataList).ToStorage();
if (seedType.GetCustomAttribute<IgnoreUpdateSeedAttribute>() == null) // 有忽略更新种子特性时则不更新 if (seedType.GetCustomAttribute<IgnoreUpdateSeedAttribute>() == null) // 有忽略更新种子特性时则不更新
{
updateCount = storage.AsUpdateable.IgnoreColumns(entityInfo.Columns.Where(u => u.PropertyInfo.GetCustomAttribute<IgnoreUpdateSeedColumnAttribute>() != null) updateCount = storage.AsUpdateable.IgnoreColumns(entityInfo.Columns.Where(u => u.PropertyInfo.GetCustomAttribute<IgnoreUpdateSeedColumnAttribute>() != null)
.Select(u => u.PropertyName).ToArray()).ExecuteCommand(); .Select(u => u.PropertyName).ToArray()).ExecuteCommand();
}
insertCount = storage.AsInsertable.ExecuteCommand(); insertCount = storage.AsInsertable.ExecuteCommand();
} }
// 无主键则只进行插入 // 无主键则只进行插入

View File

@ -623,17 +623,18 @@ public static class SqlSugarSetup
if (entityType.GetCustomAttribute<SysTableAttribute>() != null) if (entityType.GetCustomAttribute<SysTableAttribute>() != null)
db = iTenant.GetConnectionScope(SqlSugarConst.MainConfigId); db = iTenant.GetConnectionScope(SqlSugarConst.MainConfigId);
// 按主键进行批量增加和更新
if (entityInfo.Columns.Any(u => u.IsPrimarykey)) if (entityInfo.Columns.Any(u => u.IsPrimarykey))
{ {
// 按主键进行批量增加和更新
var storage = db.StorageableByObject(seedData).ToStorage(); var storage = db.StorageableByObject(seedData).ToStorage();
storage.AsInsertable.ExecuteCommand();
if (seedType.GetCustomAttribute<IgnoreUpdateSeedAttribute>() == null) // 有忽略更新种子特性时则不更新 if (seedType.GetCustomAttribute<IgnoreUpdateSeedAttribute>() == null) // 有忽略更新种子特性时则不更新
storage.AsUpdateable.IgnoreColumns(entityInfo.Columns.Where(c => c.PropertyInfo.GetCustomAttribute<IgnoreUpdateSeedColumnAttribute>() != null).Select(c => c.PropertyName).ToArray()).ExecuteCommand(); storage.AsUpdateable.IgnoreColumns(entityInfo.Columns.Where(c => c.PropertyInfo.GetCustomAttribute<IgnoreUpdateSeedColumnAttribute>() != null)
.Select(c => c.PropertyName).ToArray()).ExecuteCommand();
storage.AsInsertable.ExecuteCommand();
} }
// 无主键则只进行插入
else else
{ {
// 无主键则只进行插入
if (!db.Queryable(entityInfo.DbTableName, entityInfo.DbTableName).Any()) if (!db.Queryable(entityInfo.DbTableName, entityInfo.DbTableName).Any())
db.InsertableByObject(seedData).ExecuteCommand(); db.InsertableByObject(seedData).ExecuteCommand();
} }

View File

@ -14,8 +14,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Furion.Xunit" Version="4.9.7.121" /> <PackageReference Include="Furion.Xunit" Version="4.9.7.123" />
<PackageReference Include="Furion.Pure" Version="4.9.7.121"> <PackageReference Include="Furion.Pure" Version="4.9.7.123">
<ExcludeAssets>compile</ExcludeAssets> <ExcludeAssets>compile</ExcludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="xunit.assert" Version="2.9.3" /> <PackageReference Include="xunit.assert" Version="2.9.3" />

View File

@ -2,7 +2,7 @@
"name": "admin.net.pro", "name": "admin.net.pro",
"type": "module", "type": "module",
"version": "2.4.33", "version": "2.4.33",
"lastBuildTime": "2025.09.15", "lastBuildTime": "2025.09.16",
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架", "description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
"author": "zuohuaijun", "author": "zuohuaijun",
"license": "MIT", "license": "MIT",
@ -81,8 +81,8 @@
"vue-router": "^4.5.1", "vue-router": "^4.5.1",
"vue-signature-pad": "^3.0.2", "vue-signature-pad": "^3.0.2",
"vue3-tree-org": "^4.2.2", "vue3-tree-org": "^4.2.2",
"vxe-pc-ui": "^4.9.29", "vxe-pc-ui": "^4.9.30",
"vxe-table": "^4.16.11", "vxe-table": "^4.16.12",
"xe-utils": "^3.7.9", "xe-utils": "^3.7.9",
"xlsx-js-style": "^1.2.0" "xlsx-js-style": "^1.2.0"
}, },
@ -90,11 +90,11 @@
"@iconify/vue": "^5.0.0", "@iconify/vue": "^5.0.0",
"@plugin-web-update-notification/vite": "^2.0.2", "@plugin-web-update-notification/vite": "^2.0.2",
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
"@types/node": "^22.18.3", "@types/node": "^22.18.4",
"@types/nprogress": "^0.2.3", "@types/nprogress": "^0.2.3",
"@types/sortablejs": "^1.15.8", "@types/sortablejs": "^1.15.8",
"@typescript-eslint/eslint-plugin": "^8.43.0", "@typescript-eslint/eslint-plugin": "^8.44.0",
"@typescript-eslint/parser": "^8.43.0", "@typescript-eslint/parser": "^8.44.0",
"@vitejs/plugin-vue": "^6.0.1", "@vitejs/plugin-vue": "^6.0.1",
"@vitejs/plugin-vue-jsx": "^5.1.1", "@vitejs/plugin-vue-jsx": "^5.1.1",
"@vue/compiler-sfc": "^3.5.21", "@vue/compiler-sfc": "^3.5.21",