Blog.Core/Blog.Core.Services/PasswordLibServices.cs
LemonNoCry 966db5ec8c
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
.NET Core / build (push) Has been cancelled
🎨 优化调整缓存性能
1.调整获取所有Key的方式,原有写法是维护一个AllKey的集合,在长时间运行后Key越来越多性能越来越低,故此优化,直接使用Redis原生API
2.优化App.GetServiceProvider的逻辑,如果是单例则直接返回RootServices
3.优化IpPolicyRateLimitSetup,使用分布式缓存,而不是MemoryCache
4.优化MiniProfilerSetup,增加注册使用Redis
5.优化DataProtectionSetup,在不使用Redis时,默认保存在临时文件夹
2024-07-18 17:47:31 +08:00

90 lines
2.8 KiB
C#

using System;
using System.Threading.Tasks;
using Blog.Core.Common;
using Blog.Core.Common.DB;
using Blog.Core.Common.Utility;
using Blog.Core.IRepository.Base;
using Blog.Core.IServices;
using Blog.Core.Model.Models;
using Blog.Core.Repository.UnitOfWorks;
using Blog.Core.Services.BASE;
using SqlSugar;
namespace Blog.Core.Services
{
public partial class PasswordLibServices : BaseServices<PasswordLib>, IPasswordLibServices
{
IBaseRepository<PasswordLib> _dal;
private readonly IUnitOfWorkManage _unitOfWorkManage;
private readonly ISqlSugarClient _db;
private SqlSugarScope db => _db as SqlSugarScope;
public PasswordLibServices(IBaseRepository<PasswordLib> dal, IUnitOfWorkManage unitOfWorkManage, ISqlSugarClient db)
{
this._dal = dal;
_unitOfWorkManage = unitOfWorkManage;
_db = db;
base.BaseDal = dal;
}
[UseTran(Propagation = Propagation.Required)]
public async Task<bool> TestTranPropagation2()
{
await _dal.Add(new PasswordLib()
{
PLID = IdGeneratorUtility.NextId(),
IsDeleted = false,
plAccountName = "aaa",
plCreateTime = DateTime.Now
});
return true;
}
[UseTran(Propagation = Propagation.Mandatory)]
public async Task<bool> TestTranPropagationNoTranError()
{
await _dal.Add(new PasswordLib()
{
IsDeleted = false,
plAccountName = "aaa",
plCreateTime = DateTime.Now
});
return true;
}
[UseTran(Propagation = Propagation.Nested)]
public async Task<bool> TestTranPropagationTran2()
{
await db.Insertable(new PasswordLib()
{
PLID = IdGeneratorUtility.NextId(),
IsDeleted = false,
plAccountName = "aaa",
plCreateTime = DateTime.Now
}).ExecuteReturnSnowflakeIdAsync();
//throw new Exception("测试嵌套事务异常回滚");
return true;
}
public async Task<bool> TestTranPropagationTran3()
{
Console.WriteLine("Begin Transaction Before:" + db.ContextID);
db.BeginTran();
Console.WriteLine("Begin Transaction After:" + db.ContextID);
Console.WriteLine("");
await db.Insertable(new PasswordLib()
{
PLID = IdGeneratorUtility.NextId(),
IsDeleted = false,
plAccountName = "aaa",
plCreateTime = DateTime.Now
}).ExecuteReturnSnowflakeIdAsync();
//throw new Exception("测试嵌套事务异常回滚");
return true;
}
}
}