添加耗时
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using PMSWPF.Data.Entities;
|
||||
|
||||
namespace PMSWPF.Data.Repositories;
|
||||
@@ -9,6 +11,8 @@ namespace PMSWPF.Data.Repositories;
|
||||
/// </summary>
|
||||
public class MqttRepository
|
||||
{
|
||||
private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取Mqtt配置
|
||||
/// </summary>
|
||||
@@ -16,9 +20,14 @@ public class MqttRepository
|
||||
/// <returns></returns>
|
||||
public async Task<DbMqtt> GetByIdAsync(int id)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Queryable<DbMqtt>().In(id).SingleAsync();
|
||||
var result = await _db.Queryable<DbMqtt>().In(id).SingleAsync();
|
||||
stopwatch.Stop();
|
||||
Logger.Info($"根据ID '{id}' 获取Mqtt配置耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +37,14 @@ public class MqttRepository
|
||||
/// <returns></returns>
|
||||
public async Task<List<DbMqtt>> GetAllAsync()
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Queryable<DbMqtt>().ToListAsync();
|
||||
var result = await _db.Queryable<DbMqtt>().ToListAsync();
|
||||
stopwatch.Stop();
|
||||
Logger.Info($"获取所有Mqtt配置耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,9 +55,14 @@ public class MqttRepository
|
||||
/// <returns></returns>
|
||||
public async Task<int> AddAsync(DbMqtt mqtt)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Insertable(mqtt).ExecuteReturnIdentityAsync();
|
||||
var result = await _db.Insertable(mqtt).ExecuteReturnIdentityAsync();
|
||||
stopwatch.Stop();
|
||||
Logger.Info($"新增Mqtt配置 '{mqtt.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +73,14 @@ public class MqttRepository
|
||||
/// <returns></returns>
|
||||
public async Task<int> UpdateAsync(DbMqtt mqtt)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Updateable(mqtt).ExecuteCommandAsync();
|
||||
var result = await _db.Updateable(mqtt).ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
Logger.Info($"更新Mqtt配置 '{mqtt.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,9 +91,14 @@ public class MqttRepository
|
||||
/// <returns></returns>
|
||||
public async Task<int> DeleteAsync(int id)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Deleteable<DbMqtt>().In(id).ExecuteCommandAsync();
|
||||
var result = await _db.Deleteable<DbMqtt>().In(id).ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
Logger.Info($"删除Mqtt配置ID '{id}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user