Skip to content

Commit

Permalink
Remove unnecessary caching in repository methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickdewid committed Aug 8, 2024
1 parent 306103f commit b809bed
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/FunderMaps.Data/Repositories/IncidentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/FunderMaps.Data/Repositories/InquiryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/FunderMaps.Data/Repositories/InquirySampleRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/FunderMaps.Data/Repositories/OrganizationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SELECT COUNT(*)

public override async Task DeleteAsync(Guid id)
{
ResetCacheEntity(id);
Cache.Remove(id);

var sql = @"
DELETE
Expand Down Expand Up @@ -94,7 +94,7 @@ public async IAsyncEnumerable<Organization> ListAllAsync(Navigation navigation)

public override async Task UpdateAsync(Organization entity)
{
ResetCacheEntity(entity);
Cache.Remove(entity.Id);

var sql = @"
UPDATE application.organization
Expand Down
6 changes: 3 additions & 3 deletions src/FunderMaps.Data/Repositories/RecoveryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ SELECT COUNT(*)

public async Task DeleteAsync(int id, Guid tenantId)
{
ResetCacheEntity(id);
Cache.Remove(id);

var sql = @"
DELETE
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/FunderMaps.Data/Repositories/UserRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -233,7 +233,7 @@ public async IAsyncEnumerable<User> ListAllAsync(Navigation navigation)

public override async Task UpdateAsync(User entity)
{
ResetCacheEntity(entity);
Cache.Remove(entity.Id);

var sql = @"
UPDATE application.user
Expand Down
17 changes: 0 additions & 17 deletions src/FunderMaps.Data/RepositoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,6 @@ namespace FunderMaps.Data;
internal abstract class RepositoryBase<TEntity, TEntityPrimaryKey> : DbServiceBase, IAsyncRepository<TEntity, TEntityPrimaryKey>
where TEntity : IEntityIdentifier<TEntityPrimaryKey>
{
/// <summary>
/// Remove entity from cache.
/// </summary>
protected void ResetCacheEntity(TEntityPrimaryKey key)
{
if (key is not null)
{
Cache.Remove(key);
}
}

/// <summary>
/// Remove entity from cache.
/// </summary>
protected void ResetCacheEntity(TEntity value)
=> ResetCacheEntity(value.Id);

// TODO: Remove
// FUTURE: Maybe too npgsql specific.
// FUTURE: Extension ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,6 @@ async Task<User> IAsyncRepository<User, Guid>.GetByIdAsync(Guid id)
{
return await GetByIdAsync(id);
}

// IAsyncEnumerable<User> IAsyncRepository<User, Guid>.ListAllAsync(Navigation navigation)
// {
// return ListAllAsync(navigation);
// }
}

internal class MemoryOrganizationRepository : MemoryRepositoryBase<Organization, Guid>, IOrganizationRepository
Expand Down

0 comments on commit b809bed

Please sign in to comment.