From b809bed6f95c4e950838d5e8387565290b479b6b Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Thu, 8 Aug 2024 13:24:45 +0200 Subject: [PATCH] Remove unnecessary caching in repository methods --- .../Repositories/IncidentRepository.cs | 2 +- .../Repositories/InquiryRepository.cs | 4 ++-- .../Repositories/InquirySampleRepository.cs | 4 ++-- .../Repositories/OrganizationRepository.cs | 4 ++-- .../Repositories/RecoveryRepository.cs | 6 +++--- .../Repositories/UserRepository.cs | 4 ++-- src/FunderMaps.Data/RepositoryBase.cs | 17 ----------------- .../FunderMapsWebApplicationFactory.cs | 5 ----- 8 files changed, 12 insertions(+), 34 deletions(-) diff --git a/src/FunderMaps.Data/Repositories/IncidentRepository.cs b/src/FunderMaps.Data/Repositories/IncidentRepository.cs index feb22b3a..e958268f 100644 --- a/src/FunderMaps.Data/Repositories/IncidentRepository.cs +++ b/src/FunderMaps.Data/Repositories/IncidentRepository.cs @@ -201,7 +201,7 @@ FROM report.incident AS i public override async Task UpdateAsync(Incident entity) { - ResetCacheEntity(entity); + Cache.Remove(entity.Id); var sql = @" UPDATE report.incident diff --git a/src/FunderMaps.Data/Repositories/InquiryRepository.cs b/src/FunderMaps.Data/Repositories/InquiryRepository.cs index 6a17f38d..3693eac5 100644 --- a/src/FunderMaps.Data/Repositories/InquiryRepository.cs +++ b/src/FunderMaps.Data/Repositories/InquiryRepository.cs @@ -345,7 +345,7 @@ FROM report.inquiry_sample AS s public override async Task UpdateAsync(Inquiry entity) { - ResetCacheEntity(entity); + Cache.Remove(entity.Id); var sql = @" -- Attribution @@ -388,7 +388,7 @@ FROM application.attribution AS a public async Task SetAuditStatusAsync(int id, Inquiry entity, Guid tenantId) { - ResetCacheEntity(id); + Cache.Remove(id); var sql = @" UPDATE report.inquiry AS i diff --git a/src/FunderMaps.Data/Repositories/InquirySampleRepository.cs b/src/FunderMaps.Data/Repositories/InquirySampleRepository.cs index c1dad07c..6eb97574 100644 --- a/src/FunderMaps.Data/Repositories/InquirySampleRepository.cs +++ b/src/FunderMaps.Data/Repositories/InquirySampleRepository.cs @@ -199,7 +199,7 @@ FROM report.inquiry_sample AS s public async Task DeleteAsync(int id, Guid tenantId) { - ResetCacheEntity(id); + Cache.Remove(id); var sql = @" DELETE @@ -765,7 +765,7 @@ FROM report.inquiry_sample AS s public async Task UpdateAsync(InquirySample entity, Guid tenantId) { - ResetCacheEntity(entity); + Cache.Remove(entity.Id); var sql = @" UPDATE report.inquiry_sample AS s diff --git a/src/FunderMaps.Data/Repositories/OrganizationRepository.cs b/src/FunderMaps.Data/Repositories/OrganizationRepository.cs index 08e32e97..4c2a68ae 100644 --- a/src/FunderMaps.Data/Repositories/OrganizationRepository.cs +++ b/src/FunderMaps.Data/Repositories/OrganizationRepository.cs @@ -21,7 +21,7 @@ SELECT COUNT(*) public override async Task DeleteAsync(Guid id) { - ResetCacheEntity(id); + Cache.Remove(id); var sql = @" DELETE @@ -94,7 +94,7 @@ public async IAsyncEnumerable ListAllAsync(Navigation navigation) public override async Task UpdateAsync(Organization entity) { - ResetCacheEntity(entity); + Cache.Remove(entity.Id); var sql = @" UPDATE application.organization diff --git a/src/FunderMaps.Data/Repositories/RecoveryRepository.cs b/src/FunderMaps.Data/Repositories/RecoveryRepository.cs index 8edd4655..a0867e2d 100644 --- a/src/FunderMaps.Data/Repositories/RecoveryRepository.cs +++ b/src/FunderMaps.Data/Repositories/RecoveryRepository.cs @@ -118,7 +118,7 @@ SELECT COUNT(*) public async Task DeleteAsync(int id, Guid tenantId) { - ResetCacheEntity(id); + Cache.Remove(id); var sql = @" DELETE @@ -317,7 +317,7 @@ FROM report.recovery_sample AS s public override async Task UpdateAsync(Recovery entity) { - ResetCacheEntity(entity); + Cache.Remove(entity.Id); var sql = @" -- Attribution @@ -356,7 +356,7 @@ FROM application.attribution AS a public async Task SetAuditStatusAsync(int id, Recovery entity, Guid tenantId) { - ResetCacheEntity(id); + Cache.Remove(id); var sql = @" UPDATE report.recovery AS r diff --git a/src/FunderMaps.Data/Repositories/UserRepository.cs b/src/FunderMaps.Data/Repositories/UserRepository.cs index 243d6e27..19b7aa54 100644 --- a/src/FunderMaps.Data/Repositories/UserRepository.cs +++ b/src/FunderMaps.Data/Repositories/UserRepository.cs @@ -48,7 +48,7 @@ SELECT COUNT(*) // a ReferenceNotFoundException, which is invalid. public override async Task DeleteAsync(Guid id) { - ResetCacheEntity(id); + Cache.Remove(id); var sql = @" DELETE @@ -233,7 +233,7 @@ public async IAsyncEnumerable ListAllAsync(Navigation navigation) public override async Task UpdateAsync(User entity) { - ResetCacheEntity(entity); + Cache.Remove(entity.Id); var sql = @" UPDATE application.user diff --git a/src/FunderMaps.Data/RepositoryBase.cs b/src/FunderMaps.Data/RepositoryBase.cs index 16363e9c..0fc5b45d 100644 --- a/src/FunderMaps.Data/RepositoryBase.cs +++ b/src/FunderMaps.Data/RepositoryBase.cs @@ -13,23 +13,6 @@ namespace FunderMaps.Data; internal abstract class RepositoryBase : DbServiceBase, IAsyncRepository where TEntity : IEntityIdentifier { - /// - /// Remove entity from cache. - /// - protected void ResetCacheEntity(TEntityPrimaryKey key) - { - if (key is not null) - { - Cache.Remove(key); - } - } - - /// - /// Remove entity from cache. - /// - protected void ResetCacheEntity(TEntity value) - => ResetCacheEntity(value.Id); - // TODO: Remove // FUTURE: Maybe too npgsql specific. // FUTURE: Extension ? diff --git a/tests/FunderMaps.Webservice.Tests/FunderMapsWebApplicationFactory.cs b/tests/FunderMaps.Webservice.Tests/FunderMapsWebApplicationFactory.cs index 3cf0370f..17af4cbd 100644 --- a/tests/FunderMaps.Webservice.Tests/FunderMapsWebApplicationFactory.cs +++ b/tests/FunderMaps.Webservice.Tests/FunderMapsWebApplicationFactory.cs @@ -265,11 +265,6 @@ async Task IAsyncRepository.GetByIdAsync(Guid id) { return await GetByIdAsync(id); } - - // IAsyncEnumerable IAsyncRepository.ListAllAsync(Navigation navigation) - // { - // return ListAllAsync(navigation); - // } } internal class MemoryOrganizationRepository : MemoryRepositoryBase, IOrganizationRepository