review struttura recupero dati da SQL paginati
This commit is contained in:
@@ -101,6 +101,12 @@ namespace MP.Stats.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
protected string getCacheKeyPaged(string TableName, SelectData CurrFilter)
|
||||
{
|
||||
string answ = $"{TableName}:M_{CurrFilter.IdxMacchina}:A_{CurrFilter.PageNum}:K_{CurrFilter.KeyRichiesta}:O_{CurrFilter.IdxOdl}:D_{CurrFilter.DateStart:yyMMddHHmm}_{CurrFilter.DateEnd:yyMMddHHmm}:R_{CurrFilter.FirstRecord}_{CurrFilter.FirstRecord + CurrFilter.NumRecord}";
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Public Methods
|
||||
@@ -212,7 +218,7 @@ namespace MP.Stats.Data
|
||||
{
|
||||
//return Task.FromResult(dbController.StatDdbGetAll(numRecord, searchVal).ToArray());
|
||||
List<MP.Data.DatabaseModels.DdbTurni> dbResult = new List<MP.Data.DatabaseModels.DdbTurni>();
|
||||
string cacheKey = getCacheKey("MP:STATS:DDBT", CurrFilter);
|
||||
string cacheKey = getCacheKeyPaged("MP:STATS:DDBT", CurrFilter);
|
||||
string rawData;
|
||||
var redisDataList = await distributedCache.GetAsync(cacheKey);
|
||||
if (redisDataList != null)
|
||||
@@ -224,7 +230,7 @@ namespace MP.Stats.Data
|
||||
{
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = dbController.StatDdbGetAll(CurrFilter.DateStart, CurrFilter.DateEnd, CurrFilter.IdxMacchina, CurrFilter.IdxOdl, CurrFilter.KeyRichiesta, CurrFilter.CodArticolo);
|
||||
dbResult = dbController.StatDdbGetAll(CurrFilter.DateStart, CurrFilter.DateEnd, CurrFilter.IdxMacchina, CurrFilter.IdxOdl, CurrFilter.KeyRichiesta, CurrFilter.CodArticolo, CurrFilter.FirstRecord, CurrFilter.NumRecord);
|
||||
rawData = JsonConvert.SerializeObject(dbResult);
|
||||
redisDataList = Encoding.UTF8.GetBytes(rawData);
|
||||
await distributedCache.SetAsync(cacheKey, redisDataList, cacheOpt);
|
||||
@@ -235,6 +241,32 @@ namespace MP.Stats.Data
|
||||
return await Task.FromResult(dbResult);
|
||||
}
|
||||
|
||||
public async Task<int> StatDdbGetCount(SelectData CurrFilter, string searchVal = "")
|
||||
{
|
||||
int numRec = 0;
|
||||
string cacheKey = getCacheKeyPaged("MP:STATS:DDBT-COUNT", CurrFilter);
|
||||
string rawData;
|
||||
var redisDataList = await distributedCache.GetAsync(cacheKey);
|
||||
if (redisDataList != null)
|
||||
{
|
||||
rawData = Encoding.UTF8.GetString(redisDataList);
|
||||
int.TryParse(rawData, out numRec);
|
||||
}
|
||||
else
|
||||
{
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
numRec = dbController.StatDdbGetCount(CurrFilter.DateStart, CurrFilter.DateEnd, CurrFilter.IdxMacchina, CurrFilter.IdxOdl, CurrFilter.KeyRichiesta, CurrFilter.CodArticolo);
|
||||
rawData = $"{numRec}";
|
||||
redisDataList = Encoding.UTF8.GetBytes(rawData);
|
||||
await distributedCache.SetAsync(cacheKey, redisDataList, cacheOpt);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Info($"Effettuata lettura da DB + caching per DdbTurni: {ts.TotalMilliseconds} ms");
|
||||
}
|
||||
return await Task.FromResult(numRec);
|
||||
}
|
||||
|
||||
public async Task<List<MP.Data.DatabaseModels.ODL>> StatOdlGetAll(SelectData CurrFilter, string searchVal = "")
|
||||
{
|
||||
//return Task.FromResult(dbController.StatOdlGetAll(numRecord, searchVal));
|
||||
|
||||
@@ -12,10 +12,38 @@ namespace MP.Stats.Data
|
||||
public string CodArticolo { get; set; } = "*";
|
||||
public DateTime DateEnd { get; set; } = DateTime.Now.AddMinutes(1);
|
||||
public DateTime DateStart { get; set; } = DateTime.Now.AddDays(-7);
|
||||
|
||||
/// <summary>
|
||||
/// Primo record x selezione paginata, tipicamente primo della "decina" della pagina corrente
|
||||
/// </summary>
|
||||
public int FirstRecord
|
||||
{
|
||||
get
|
||||
{
|
||||
int primaPag = PageNum % 10;
|
||||
int decina = PageNum - primaPag;
|
||||
return PageSize * decina + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public string IdxMacchina { get; set; } = "*";
|
||||
public int IdxOdl { get; set; } = -999;
|
||||
public string KeyRichiesta { get; set; } = "*";
|
||||
|
||||
/// <summary>
|
||||
/// Numero record da recuperare, tipicamente la decina della pag corrente (10 * PageSize)
|
||||
/// </summary>
|
||||
public int NumRecord
|
||||
{
|
||||
get
|
||||
{
|
||||
return PageSize * 10;
|
||||
}
|
||||
}
|
||||
|
||||
public int PageNum { get; set; } = 1;
|
||||
public int PageSize { get; set; } = 10;
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
@@ -44,6 +72,10 @@ namespace MP.Stats.Data
|
||||
if (!(obj is SelectData item))
|
||||
return false;
|
||||
|
||||
if (PageSize != item.PageSize)
|
||||
return false;
|
||||
if (PageNum != item.PageNum)
|
||||
return false;
|
||||
if (CodArticolo != item.CodArticolo)
|
||||
return false;
|
||||
if (DateEnd != item.DateEnd)
|
||||
|
||||
Reference in New Issue
Block a user