adding caching to get value sum
All checks were successful
API and ETL Build / build_etl (push) Successful in 3s
API and ETL Build / build_api (push) Successful in 10s

This commit is contained in:
Jose Henrique 2025-06-13 11:47:39 -03:00
parent 23256245a0
commit 87a98fefb1

View File

@ -77,11 +77,15 @@ namespace OpenCand.API.Repository
} }
public async Task<List<GetValueSumResponse>> GetValueSum(string query, Dictionary<string, object>? parameters = null) public async Task<List<GetValueSumResponse>> GetValueSum(string query, Dictionary<string, object>? parameters = null)
{
string cacheKey = GenerateCacheKey(query.GetHashCode().ToString());
return await GetOrSetCacheAsync(cacheKey, async () =>
{ {
using (var connection = new NpgsqlConnection(ConnectionString)) using (var connection = new NpgsqlConnection(ConnectionString))
{ {
return (await connection.QueryAsync<GetValueSumResponse>(query, parameters)).AsList(); return (await connection.QueryAsync<GetValueSumResponse>(query, parameters)).AsList();
} }
}) ?? new List<GetValueSumResponse>();
} }
} }
} }