|
|
|
|
@ -1,42 +1,46 @@
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
using Enyim.Caching;
|
|
|
|
|
using Expedience.Infrastructure.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace Expedience.Infrastructure
|
|
|
|
|
namespace Expedience.Infrastructure;
|
|
|
|
|
|
|
|
|
|
public interface IExpedienceRepository
|
|
|
|
|
{
|
|
|
|
|
ValueTask<List<DutyCompletionRecord>> GetDutyCompletionRecords(string expac, CancellationToken cancellationToken);
|
|
|
|
|
ValueTask<List<DeepDungeonRecord>> GetDeepDungeonRecords(CancellationToken cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ExpedienceRepository : IExpedienceRepository
|
|
|
|
|
{
|
|
|
|
|
public interface IExpedienceRepository : IDisposable
|
|
|
|
|
private readonly ExpedienceContext _dbContext;
|
|
|
|
|
private readonly IMemcachedClient _memcachedClient;
|
|
|
|
|
|
|
|
|
|
public ExpedienceRepository(ExpedienceContext dbContext, IMemcachedClient memcachedClient)
|
|
|
|
|
{
|
|
|
|
|
Task<List<DutyCompletionRecord>> GetDutyCompletionRecords(string expac, CancellationToken cancellationToken);
|
|
|
|
|
_dbContext = dbContext;
|
|
|
|
|
_memcachedClient = memcachedClient;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ExpedienceRepository : IExpedienceRepository
|
|
|
|
|
public async ValueTask<List<DutyCompletionRecord>> GetDutyCompletionRecords(string expac, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
private readonly ExpedienceContext _dbContext;
|
|
|
|
|
private readonly IMemcachedClient _memcachedClient;
|
|
|
|
|
|
|
|
|
|
public ExpedienceRepository(ExpedienceContext dbContext, IMemcachedClient memcachedClient)
|
|
|
|
|
{
|
|
|
|
|
_dbContext = dbContext;
|
|
|
|
|
_memcachedClient = memcachedClient;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<DutyCompletionRecord>> GetDutyCompletionRecords(string expac, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var cacheKey = $"xpd-dcr-{expac}";
|
|
|
|
|
var cacheSeconds = 600;
|
|
|
|
|
var records = await _memcachedClient.GetValueOrCreateAsync(cacheKey, cacheSeconds,
|
|
|
|
|
async () => await _dbContext.DutyCompletionRecords.FromSqlInterpolated($"SELECT * FROM public.get_dutycompletionrecords({expac})")
|
|
|
|
|
.ToListAsync());
|
|
|
|
|
|
|
|
|
|
return records;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
//_memcachedClient.Dispose();
|
|
|
|
|
}
|
|
|
|
|
var cacheKey = $"xpd-dcr-{expac}";
|
|
|
|
|
var cacheSeconds = 600;
|
|
|
|
|
var records = await _memcachedClient.GetValueOrCreateAsync(cacheKey, cacheSeconds,
|
|
|
|
|
async () => await _dbContext.DutyCompletionRecords.FromSqlInterpolated($"SELECT * FROM public.get_dutycompletionrecords({expac})")
|
|
|
|
|
.ToListAsync(cancellationToken));
|
|
|
|
|
|
|
|
|
|
return records;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async ValueTask<List<DeepDungeonRecord>> GetDeepDungeonRecords(CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var cacheKey = $"xpd-dd";
|
|
|
|
|
var cacheSeconds = 600;
|
|
|
|
|
var records = await _memcachedClient.GetValueOrCreateAsync(cacheKey, cacheSeconds,
|
|
|
|
|
async () => await _dbContext.DeepDungeonRecords.FromSqlInterpolated($"SELECT * FROM public.get_deepdungeonresults()")
|
|
|
|
|
.ToListAsync(cancellationToken));
|
|
|
|
|
|
|
|
|
|
return records;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|