Update metodi async con FusionCache
This commit is contained in:
@@ -13,6 +13,8 @@ namespace MP.Core
|
||||
public const string redisAnagGruppi = redisBaseAddr + "Cache:AnagGruppi";
|
||||
public const string redisAnagStati = redisBaseAddr + "Cache:AnagStati";
|
||||
|
||||
public const string redisLinkMenu = redisBaseAddr + "Cache:LinkMenu";
|
||||
|
||||
public const string redisArtByDossier = redisBaseAddr + "Cache:ArtByDossier";
|
||||
|
||||
public const string redisArtList = redisBaseAddr + "Cache:ArtList";
|
||||
|
||||
@@ -2531,17 +2531,15 @@ namespace MP.Data.Controllers
|
||||
/// <param name="KitCode"></param>
|
||||
/// <param name="codChild"></param>
|
||||
/// <returns></returns>
|
||||
public List<TemplateKitModel> TemplateKitFilt(string KitCode, string codChild)
|
||||
public async Task<List<TemplateKitModel>> TemplateKitFiltAsync(string KitCode, string codChild)
|
||||
{
|
||||
List<TemplateKitModel> dbResult = new List<TemplateKitModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetTempKit
|
||||
.Where(x => (string.IsNullOrEmpty(KitCode) && string.IsNullOrEmpty(codChild)) || (x.CodArtParent.Contains(KitCode) && !string.IsNullOrEmpty(KitCode)) || (x.CodArtChild.Contains(codChild) && !string.IsNullOrEmpty(codChild)))
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
dbResult = await dbCtx
|
||||
.DbSetTempKit
|
||||
.Where(x => (string.IsNullOrEmpty(KitCode) && string.IsNullOrEmpty(codChild)) || (x.CodArtParent.Contains(KitCode) && !string.IsNullOrEmpty(KitCode)) || (x.CodArtChild.Contains(codChild) && !string.IsNullOrEmpty(codChild)))
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
|
||||
@@ -3498,7 +3498,7 @@ namespace MP.Data.Services
|
||||
result = new List<TemplateKitModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"TemplateKitFilt | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"TemplateKitFiltAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -290,6 +290,7 @@ namespace MP.SPEC.Data
|
||||
);
|
||||
}
|
||||
|
||||
#if false
|
||||
public async Task<List<ListValuesModel>> AnagTipoArtLvAsync()
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("AnagTipoArtLvAsync");
|
||||
@@ -318,6 +319,22 @@ namespace MP.SPEC.Data
|
||||
activity?.Stop();
|
||||
LogTrace($"AnagTipoArtLvAsync Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce elenco tipi articolo livello anagrafica
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<ListValuesModel>> AnagTipoArtLvAsync()
|
||||
{
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "AnagTipoArtLvAsync",
|
||||
cacheKey: Utils.redisTipoArt,
|
||||
expiration: TimeSpan.FromMinutes(redisLongTimeCache),
|
||||
fetchFunc: async () => await dbController.AnagTipoArtLvAsync() ?? new List<ListValuesModel>(),
|
||||
tagList: [Utils.redisTipoArt]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -835,18 +852,18 @@ namespace MP.SPEC.Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco link validi
|
||||
/// Elenco link validi per il menu
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<LinkMenuModel>> ElencoLinkAsync()
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("ElencoLinkAsync");
|
||||
string source = "DB";
|
||||
var linkList = await dbController.ElencoLinkAsync();
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"ElencoLinkAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return linkList;
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "ElencoLinkAsync",
|
||||
cacheKey: Utils.redisLinkMenu,
|
||||
expiration: TimeSpan.FromMinutes(redisLongTimeCache),
|
||||
fetchFunc: async () => await dbController.ElencoLinkAsync() ?? new List<LinkMenuModel>(),
|
||||
tagList: [Utils.redisLinkMenu]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1797,6 +1814,28 @@ namespace MP.SPEC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<string>> MachineWithOdlAsync()
|
||||
{
|
||||
string redisKey = Utils.redisOdlCurrByMac;
|
||||
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "MachineWithOdlAsync",
|
||||
cacheKey: redisKey,
|
||||
expiration: TimeSpan.FromSeconds(3),
|
||||
fetchFunc: async () =>
|
||||
{
|
||||
var rawData = await dbController.OdlGetCurrentAsync();
|
||||
var dbResult = rawData
|
||||
.Select(x => x.IdxMacchina)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
return dbResult ?? new List<string>();
|
||||
},
|
||||
tagList: [Utils.redisOdlCurrByMac]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero info Machine-IOB x TAB (da info registrate IOB-WIN --> MP-IO)
|
||||
/// </summary>
|
||||
@@ -2000,28 +2039,6 @@ namespace MP.SPEC.Data
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<List<string>> MachineWithOdlAsync()
|
||||
{
|
||||
string redisKey = Utils.redisOdlCurrByMac;
|
||||
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "MachineWithOdlAsync",
|
||||
cacheKey: redisKey,
|
||||
expiration: TimeSpan.FromSeconds(3),
|
||||
fetchFunc: async () =>
|
||||
{
|
||||
var rawData = await dbController.OdlGetCurrentAsync();
|
||||
var dbResult = rawData
|
||||
.Select(x => x.IdxMacchina)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
return dbResult ?? new List<string>();
|
||||
},
|
||||
tagList: [Utils.redisOdlCurrByMac]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ODL correnti (tutti)
|
||||
/// </summary>
|
||||
@@ -2770,33 +2787,23 @@ namespace MP.SPEC.Data
|
||||
/// <summary>
|
||||
/// Elenco Template KIT da ricerca
|
||||
/// </summary>
|
||||
/// <param name="codParent"></param>
|
||||
/// <param name="codChild"></param>
|
||||
/// <param name="codParent">Codice articolo padre</param>
|
||||
/// <param name="codChild">Codice articolo figlio</param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<TemplateKitModel>> TemplateKitFiltAsync(string codParent, string codChild)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("TemplateKitFiltAsync");
|
||||
string source = "DB";
|
||||
List<TemplateKitModel>? result = new List<TemplateKitModel>();
|
||||
// cerco in redis...
|
||||
string currKey = $"{Utils.redisKitTempl}:{codParent}:{codChild}";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<TemplateKitModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.TemplateKitFilt(codParent, codChild);
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromMinutes(redisLongTimeCache));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<TemplateKitModel>();
|
||||
}
|
||||
|
||||
var result = await GetOrFetchAsync(
|
||||
operationName: "TemplateKitFiltAsync",
|
||||
cacheKey: currKey,
|
||||
expiration: TimeSpan.FromMinutes(redisLongTimeCache),
|
||||
fetchFunc: async () => await dbController.TemplateKitFiltAsync(codParent, codChild) ?? new List<TemplateKitModel>(),
|
||||
tagList: [Utils.redisKitTempl]
|
||||
);
|
||||
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.SetTag("result.count", result.Count);
|
||||
activity?.Stop();
|
||||
@@ -3312,9 +3319,11 @@ namespace MP.SPEC.Data
|
||||
case "DB":
|
||||
LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms", reqLevel: NLog.LogLevel.Info);
|
||||
break;
|
||||
|
||||
case "REDIS":
|
||||
LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms", reqLevel: NLog.LogLevel.Debug);
|
||||
break;
|
||||
|
||||
default:
|
||||
LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user