fix(dal): при формировании групповых шорткодов не хватало include GroupType, изменен ключ кэширования

This commit is contained in:
Mikhail Kuznetsov
2025-12-24 11:25:25 +10:00
parent bcb2272943
commit b5bbc52473
6 changed files with 71 additions and 34 deletions

View File

@@ -2,7 +2,8 @@
using PARR.DAL.CacheServices;
using PARR.DAL.DomainServices.Interfaces;
using PARR.DAL.Settings;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using System.Text;
namespace PARR.DAL.DomainServices.Implementations
{
@@ -23,6 +24,7 @@ namespace PARR.DAL.DomainServices.Implementations
}
public async Task<string> GetAggregatedValueAsync(
Guid jobGroupId,
Guid unitId,
string shortcode,
Func<Task<string>> computeIfMissing)
@@ -30,7 +32,7 @@ namespace PARR.DAL.DomainServices.Implementations
if (string.IsNullOrEmpty(shortcode))
throw new ArgumentException("Ключ шорткода должен быть указан.", nameof(shortcode));
var cacheKey = GetCacheKey(unitId, shortcode);
var cacheKey = GetCacheKey(jobGroupId, unitId, shortcode);
try
{
@@ -68,7 +70,7 @@ namespace PARR.DAL.DomainServices.Implementations
}
}
private static string GetCacheKey(Guid unitId, string shortcodeKey)
private static string GetCacheKey(Guid jobGroupId, Guid unitId, string shortcodeKey)
{
var safeKey = shortcodeKey
.Trim()
@@ -81,9 +83,13 @@ namespace PARR.DAL.DomainServices.Implementations
.Replace("/", "_")
.Replace("\\", "_");
safeKey = Regex.Replace(safeKey, @"[^a-zA-Z0-9_-]", "_");
// ✅ SHA256 от safeKey
using var sha256 = SHA256.Create();
var hashBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(safeKey));
var hashHex = BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
return $"gr_shcd_{unitId:N}_{safeKey}"; // :N — без дефисов в Guid
// ✅ Новый формат ключа
return $"gr_shcd_{jobGroupId:N}{unitId:N}_{hashHex}";
}
}
}