From 81c3e5bd1f1ea1ccd1bd6fbfcd21edb9ce251b4a Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 3 Sep 2024 18:51:32 +0200 Subject: [PATCH] Fix cleanup - redis - obj non usati --- MP.Land/Data/AppAuthService.cs | 93 +++++++++++++++++------------- MP.Land/Data/LicenseService.cs | 29 ---------- MP.Land/Shared/MainLayout.razor.cs | 1 - MP.Land/Shared/NavMenu.razor.cs | 4 +- 4 files changed, 55 insertions(+), 72 deletions(-) diff --git a/MP.Land/Data/AppAuthService.cs b/MP.Land/Data/AppAuthService.cs index 3c052c46..0ce151e2 100644 --- a/MP.Land/Data/AppAuthService.cs +++ b/MP.Land/Data/AppAuthService.cs @@ -257,6 +257,15 @@ namespace MP.Land.Data MpDbController.Dispose(); } + public async Task FlushRedisCache() + { + RedisValue pattern = new RedisValue($"{redisBaseAddr}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + // reset in RAM + Vocabolario = new Dictionary(); + CheckVoc(); + } + /// /// Elenco permessi dato utente /// @@ -307,42 +316,6 @@ namespace MP.Land.Data return dbResult; } - public async Task FlushRedisCache() - { - RedisValue pattern = new RedisValue($"{redisBaseAddr}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - // reset in RAM - Vocabolario = new Dictionary(); - await CheckVoc(); - } - - /// - /// Esegue flush memoria redis dato pattern - /// - /// - /// - private async Task ExecFlushRedisPattern(RedisValue pattern) - { - bool answ = false; - var listEndpoints = redisConn.GetEndPoints(); - foreach (var endPoint in listEndpoints) - { - //var server = redisConnAdmin.GetServer(listEndpoints[0]); - var server = redisConn.GetServer(endPoint); - if (server != null) - { - var keyList = server.Keys(redisDb.Database, pattern); - foreach (var item in keyList) - { - await redisDb.KeyDeleteAsync(item); - } - answ = true; - } - } - - return answ; - } - public string Traduci(string lemma, string lingua = "IT") { string answ = $"__{lemma}__"; @@ -420,7 +393,7 @@ namespace MP.Land.Data #region Protected Methods - protected async Task CheckVoc() + protected void CheckVoc() { if (Vocabolario.Count == 0) { @@ -428,7 +401,7 @@ namespace MP.Land.Data string currKey = $"{redisBaseAddr}:MP:VOCAB"; Stopwatch sw = new Stopwatch(); sw.Start(); - string? rawData = await redisDb.StringGetAsync(currKey); + string? rawData = redisDb.StringGet(currKey); if (!string.IsNullOrEmpty(rawData) && rawData.Length > 2) { source = "REDIS"; @@ -437,9 +410,11 @@ namespace MP.Land.Data } else { - Vocabolario = dbController.VocabolarioGetAll().ToDictionary(x => $"{x.Lingua}#{x.Lemma}", x => x.Traduzione); + Vocabolario = dbController + .VocabolarioGetAll() + .ToDictionary(x => $"{x.Lingua}#{x.Lemma}", x => x.Traduzione); rawData = JsonConvert.SerializeObject(Vocabolario); - await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + redisDb.StringSet(currKey, rawData, UltraLongCache); } sw.Stop(); Log.Trace($"Rilettura Vocabolario | {source} | {sw.ElapsedMilliseconds} ms"); @@ -454,11 +429,17 @@ namespace MP.Land.Data private const string redisBaseAddr = "MP:LAND"; private const string rKeyDirittiUser = $"{redisBaseAddr}:DIR_USER"; + private const string rKeyPermUser = $"{redisBaseAddr}:PERM_USER"; + private static IConfiguration _configuration; + private static ILogger _logger; + private static List ElencoMacchine = new List(); + private static JsonSerializerSettings? JSSettings; + private static Logger Log = LogManager.GetCurrentClassLogger(); private static string Modulo = ""; @@ -485,6 +466,7 @@ namespace MP.Land.Data private IDatabase redisDb = null!; private Random rnd = new Random(); + private Dictionary Vocabolario = new Dictionary(); #endregion Private Fields @@ -518,5 +500,36 @@ namespace MP.Land.Data } #endregion Private Properties + + #region Private Methods + + /// + /// Esegue flush memoria redis dato pattern + /// + /// + /// + private async Task ExecFlushRedisPattern(RedisValue pattern) + { + bool answ = false; + var listEndpoints = redisConn.GetEndPoints(); + foreach (var endPoint in listEndpoints) + { + //var server = redisConnAdmin.GetServer(listEndpoints[0]); + var server = redisConn.GetServer(endPoint); + if (server != null) + { + var keyList = server.Keys(redisDb.Database, pattern); + foreach (var item in keyList) + { + await redisDb.KeyDeleteAsync(item); + } + answ = true; + } + } + + return answ; + } + + #endregion Private Methods } } \ No newline at end of file diff --git a/MP.Land/Data/LicenseService.cs b/MP.Land/Data/LicenseService.cs index 440e8a88..6d342015 100644 --- a/MP.Land/Data/LicenseService.cs +++ b/MP.Land/Data/LicenseService.cs @@ -123,7 +123,6 @@ namespace MP.Land.Data { List dbResult = new List(); string cacheKey = $"{rKeyAttByLic}:{MasterKey}"; - trackCache(cacheKey); string rawData = await getRSV(cacheKey); if (!string.IsNullOrEmpty(rawData)) { @@ -235,7 +234,6 @@ namespace MP.Land.Data { List dbResult = new List(); string cacheKey = $"{rkeyAppInfo}:{MasterKey}"; - trackCache(cacheKey); string rawData = await getRSV(cacheKey); if (!string.IsNullOrEmpty(rawData)) { @@ -404,18 +402,6 @@ namespace MP.Land.Data return fatto; } - /// - /// Registra in cache chiave se non fosse giĆ  in elenco - /// - /// - protected void trackCache(string newKey) - { - if (!cachedDataList.Contains(newKey)) - { - cachedDataList.Add(newKey); - } - } - #endregion Protected Methods #region Private Fields @@ -434,21 +420,6 @@ namespace MP.Land.Data /// private static string rkeyAppInfo = "LongCache:AppInfo"; - /// - /// Elenco obj in cache - /// - private List cachedDataList = new List(); - - /// - /// Durata cache lunga IN SECONDI - /// - private int cacheTtlLong = 60 * 5; - - /// - /// Durata cache breve IN SECONDI - /// - private int cacheTtlShort = 60 * 1; - /// /// Oggetto per connessione a REDIS /// diff --git a/MP.Land/Shared/MainLayout.razor.cs b/MP.Land/Shared/MainLayout.razor.cs index 0ba4bfd0..058d26af 100644 --- a/MP.Land/Shared/MainLayout.razor.cs +++ b/MP.Land/Shared/MainLayout.razor.cs @@ -70,7 +70,6 @@ namespace MP.Land.Shared protected bool annualAuthOk { get; set; } = false; - private List ListRecords; #endregion Private Properties } diff --git a/MP.Land/Shared/NavMenu.razor.cs b/MP.Land/Shared/NavMenu.razor.cs index 1381eeb5..30eb547b 100644 --- a/MP.Land/Shared/NavMenu.razor.cs +++ b/MP.Land/Shared/NavMenu.razor.cs @@ -89,7 +89,7 @@ namespace MP.Land.Shared #region Private Methods - private async Task checkAuth() + private void checkAuth() { // verifico pagina tra i permessi, se manca --> rimando a pagina unauth... se contiene // index --> salto @@ -133,7 +133,7 @@ namespace MP.Land.Shared UserRight = await DataService.DirittiGetByUser(uName); UserPerm = await DataService.PermessiGetByUser(uName); } - await checkAuth(); + checkAuth(); await Task.Delay(1); isLoading = false; await Task.Delay(1);