Aggiunta cache redis alarm log
This commit is contained in:
@@ -85,6 +85,7 @@ namespace MP.MONO.Core
|
||||
|
||||
//REDIS caching keys
|
||||
public static readonly string ALARM_REC = $"{BASE_HASH}:Current:AlarmsRecVal";
|
||||
public static readonly string ALARM_LOG = $"{BASE_HASH}:Current:AlarmsLogVal";
|
||||
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
@@ -123,14 +123,14 @@ namespace MP.MONO.Data.Controllers
|
||||
/// <param name="skipRec"></param>
|
||||
/// <param name="numRec"></param>
|
||||
/// <returns></returns>
|
||||
public List<AlarmLogModel> AlarmLogGetFilt(int MachineId, int skipRec, int numRec)
|
||||
public async Task<List<AlarmLogModel>> AlarmLogGetFilt(int MachineId, int skipRec, int numRec)
|
||||
{
|
||||
List<AlarmLogModel> dbResult = new List<AlarmLogModel>();
|
||||
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
dbResult = await localDbCtx
|
||||
.DbSetAlarmLog
|
||||
.AsNoTracking()
|
||||
.Where(x => x.MachineId == MachineId)
|
||||
@@ -138,13 +138,14 @@ namespace MP.MONO.Data.Controllers
|
||||
.OrderByDescending(x => x.AlarmLogId)
|
||||
.Skip(skipRec)
|
||||
.Take(numRec)
|
||||
.ToList();
|
||||
.ToListAsync();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmLogGetFilt{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
//await Task.Delay(1);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
@@ -332,14 +333,14 @@ namespace MP.MONO.Data.Controllers
|
||||
/// <param name="skipRec"></param>
|
||||
/// <param name="numRec"></param>
|
||||
/// <returns></returns>
|
||||
public List<AlarmRecModel> AlarmRecGetFilt(int MachineId, int skipRec, int numRec)
|
||||
public async Task<List<AlarmRecModel>> AlarmRecGetFilt(int MachineId, int skipRec, int numRec)
|
||||
{
|
||||
List<AlarmRecModel> dbResult = new List<AlarmRecModel>();
|
||||
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
dbResult = await localDbCtx
|
||||
.DbSetAlarmRec
|
||||
.AsNoTracking()
|
||||
.Where(x => x.MachineId == MachineId)
|
||||
@@ -348,7 +349,7 @@ namespace MP.MONO.Data.Controllers
|
||||
.OrderByDescending(x => x.DtStart)
|
||||
.Skip(skipRec)
|
||||
.Take(numRec)
|
||||
.ToList();
|
||||
.ToListAsync();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
|
||||
@@ -7,9 +7,11 @@ using MP.MONO.Data.DbModels;
|
||||
using MP.MONO.Data.DTO;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using Org.BouncyCastle.Bcpg.OpenPgp;
|
||||
using StackExchange.Redis;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using static MP.MONO.Core.Enums;
|
||||
|
||||
@@ -117,12 +119,34 @@ namespace MP.MONO.UI.Data
|
||||
/// <returns></returns>
|
||||
public async Task<List<AlarmLogModel>> AlarmLogGetFilt(int machineId, int skipRec, int numRec)
|
||||
{
|
||||
string source = "DB";
|
||||
List<AlarmLogModel> dbResult = new List<AlarmLogModel>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
string currKey = $"{Constants.ALARM_LOG}:{machineId}:{skipRec}:{numRec}";
|
||||
stopWatch.Start();
|
||||
var dbResult = dbController.AlarmLogGetFilt(machineId, skipRec, numRec);
|
||||
string rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<AlarmLogModel>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new List<AlarmLogModel>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = await dbController.AlarmLogGetFilt(machineId, skipRec, numRec);
|
||||
rawData = JsonConvert.SerializeObject(dbResult);
|
||||
await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromMilliseconds(1000));
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB AlarmLogGetFilt: {ts.TotalMilliseconds} ms");
|
||||
Log.Debug($"AlarmLogGetFilt | {source} in : {ts.TotalMilliseconds} ms");
|
||||
return await Task.FromResult(dbResult);
|
||||
}
|
||||
/// <summary>
|
||||
@@ -190,9 +214,9 @@ namespace MP.MONO.UI.Data
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.AlarmRecGetFilt(MachineId, skipRec, numRec);
|
||||
dbResult = await dbController.AlarmRecGetFilt(MachineId, skipRec, numRec);
|
||||
rawData = JsonConvert.SerializeObject(dbResult);
|
||||
await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromMilliseconds(500));
|
||||
await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromMilliseconds(1000));
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Platforms>AnyCPU;x86;x64</Platforms>
|
||||
<Version>1.2.2210.2415</Version>
|
||||
<Version>1.2.2210.2416</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>MAPO-MONO</i>
|
||||
<h4>Version: 1.2.2210.2415</h4>
|
||||
<h4>Version: 1.2.2210.2416</h4>
|
||||
<br /> Release Note:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.2.2210.2415
|
||||
1.2.2210.2416
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>1.2.2210.2415</version>
|
||||
<version>1.2.2210.2416</version>
|
||||
<url>http://nexus.steamware.net/repository/SWS/MP.MONO.UI/stable/LAST/MP.Mon.zip</url>
|
||||
<changelog>http://nexus.steamware.net/repository/SWS/MP.MONO.UI/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user