From b250e58d61f61bb2d34c1315022cc1f0930962c6 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 28 Oct 2022 09:05:33 +0500 Subject: [PATCH] EfCacheExtensions incomplete --- .../EfCache/EfCacheExtensions.cs | 70 +++++++++++++------ .../Repository/UserRoleRepository.cs | 3 +- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/AsbCloudInfrastructure/EfCache/EfCacheExtensions.cs b/AsbCloudInfrastructure/EfCache/EfCacheExtensions.cs index e9f17c32..8d993c21 100644 --- a/AsbCloudInfrastructure/EfCache/EfCacheExtensions.cs +++ b/AsbCloudInfrastructure/EfCache/EfCacheExtensions.cs @@ -21,6 +21,54 @@ namespace AsbCloudInfrastructure.EfCache private static readonly TimeSpan minCacheTime = TimeSpan.FromSeconds(2); private static readonly TimeSpan defaultObsolescence = TimeSpan.FromMinutes(4); + private class YeldConvertedData : IEnumerable + { + IEnumerable data; + public YeldConvertedData(IEnumerable entities, Func convert) + { + data = entities; + } + + class Enumerator : IEnumerator + { + private readonly IEnumerable data; + + public Enumerator( IEnumerable data, Func convert) + { + this.data = data; + } + + public TModel Current => throw new NotImplementedException(); + + object IEnumerator.Current => throw new NotImplementedException(); + + public void Dispose() + { + throw new NotImplementedException(); + } + + public bool MoveNext() + { + throw new NotImplementedException(); + } + + public void Reset() + { + throw new NotImplementedException(); + } + } + + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } + private class CacheItem { internal IEnumerable? Data; @@ -45,14 +93,10 @@ namespace AsbCloudInfrastructure.EfCache { try { - var convertedData = typedEntityData.Select(convert).ToList(); + var convertedData = typedEntityData.Select(convert).ToArray(); Data = convertedData; return convertedData; } - catch - { - throw; - } finally { semaphore.Release(); @@ -89,10 +133,6 @@ namespace AsbCloudInfrastructure.EfCache cache = new CacheItem(); caches.Add(tag, cache); } - catch - { - throw; - } finally { semaphore.Release(); @@ -133,10 +173,6 @@ namespace AsbCloudInfrastructure.EfCache cache.DateObsolete = dateObsolete; cache.DateObsoleteTotal = dateObsolete + queryTime + minCacheTime; } - catch - { - throw; - } finally { cache.semaphore.Release(); @@ -170,10 +206,6 @@ namespace AsbCloudInfrastructure.EfCache cache = new CacheItem(); caches.Add(tag, cache); } - catch - { - throw; - } finally { semaphore.Release(); @@ -214,10 +246,6 @@ namespace AsbCloudInfrastructure.EfCache cache.DateObsolete = dateObsolete; cache.DateObsoleteTotal = dateObsolete + queryTime + minCacheTime; } - catch - { - throw; - } finally { cache.semaphore.Release(); diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index 62c9f843..1e83ccb7 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -293,9 +293,10 @@ namespace AsbCloudInfrastructure.Repository if (entity.RelationUserRoleUserRoles?.Any() == true) { + var rolesCache = GetCacheUserRole(); dto.Roles = entity.RelationUserRoleUserRoles.Select(rel => { - var dto = GetCacheUserRole().First(r => r.Id == rel.IdInclude); + var dto = rolesCache.First(r => r.Id == rel.IdInclude); var includedRole = Convert(dto); return Convert(includedRole); }).ToArray();