feat(core, infrastructure): UnitService - удаление/массовое удаление юнитов

This commit is contained in:
Mikhail Trubnikov
2026-06-01 16:10:00 +10:00
parent bdcc858bc5
commit d27d594e57
6 changed files with 80 additions and 7 deletions

View File

@@ -125,11 +125,32 @@ namespace PARR.Core.Services.UnitService.Implementations
/// <param name="id"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public Task RemoveFromCacheAsync(Guid id)
public async Task RemoveFromCacheAsync(Guid id)
{
//todo: может удалять тоже списком
var hashKey = redisCacheService.GetKey(CacheKeys.Unit.UnitHashWithBucket(id));
var unitKey = redisCacheService.GetKey(CacheKeys.Unit.UnitItem(id));
throw new NotImplementedException();
await redisCacheService.DeleteHashFieldAsync(hashKey, unitKey);
}
/// <summary>
/// Удалить записи UnitInfo из кэш
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public async Task RemoveFromCacheAsync(IReadOnlySet<Guid> ids)
{
if (ids == null || ids.Count == 0)
return;
// Формируем ключи
var keys = ids.Select(t =>
{
var (hashKey, fieldKey) = (redisCacheService.GetKey(CacheKeys.Unit.UnitHashWithBucket(t)), redisCacheService.GetKey(CacheKeys.Unit.UnitItem(t)));
return (HashKey: hashKey, FieldKey: fieldKey);
}).ToList();
await redisCacheService.DeleteHashFieldsAsync(keys);
}

View File

@@ -36,5 +36,13 @@ namespace PARR.Core.Services.UnitService.Implementations
{
await unitCacheService.RemoveFromCacheAsync(id);
}
public async Task RemoveFromCacheAsync(IEnumerable<Guid> ids)
{
// Защищаем себя от Multiple Enumeration и убираем дубликаты, если передали List
var uniqueIds = ids as IReadOnlySet<Guid> ?? ids.ToHashSet();
await unitCacheService.RemoveFromCacheAsync(uniqueIds);
}
}
}

View File

@@ -30,6 +30,11 @@ namespace PARR.Core.Services.UnitService.Interfaces
/// <returns></returns>
Task RemoveFromCacheAsync(Guid id);
/// <summary>
/// Удалить юниты из кэша
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
Task RemoveFromCacheAsync(IEnumerable<Guid> ids);
}
}