Cleanup from the Release (#2127)
* Added an FAQ link on the Kavita+ tab. * Don't query Kavita+ for ratings on comic libraries as there is no upstream provider yet. * Jumpbar keys are a little hard to click * Fixed an issue where libraries that don't allow scrobbling could be scrobbled when generating past history with read events. * Made the min/max release year on metadata filter number and removed the spin arrows for styling. * Fixed disable tabs color contrast due to bootstrap undocumented change. * Refactored whole codebase to unify caching mechanism. Upped the default cache memory amount to 75 to account for the extra data load. Still LRU. Fixed an issue where Cache key was using Port instead. Refactored all the Configuration code to use strongly typed deserialization. * Fixed an issue where get latest progress would throw an exception if there was no progress due to LINQ and MAX query. * Fixed a bug where Send to Device wasn't present on Series cards. * Hooked up the ability to change the cache size for Kavita via the UI.
This commit is contained in:
parent
1ed8889d08
commit
81da9dc444
37 changed files with 402 additions and 272 deletions
|
|
@ -11,6 +11,7 @@ using API.Helpers.Builders;
|
|||
using API.Services;
|
||||
using API.Services.Plus;
|
||||
using AutoMapper;
|
||||
using EasyCaching.Core;
|
||||
using Hangfire;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
|
@ -26,20 +27,22 @@ public class ReviewController : BaseApiController
|
|||
private readonly ILicenseService _licenseService;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IReviewService _reviewService;
|
||||
private readonly IMemoryCache _cache;
|
||||
private readonly IScrobblingService _scrobblingService;
|
||||
public const string CacheKey = "review-";
|
||||
private readonly IEasyCachingProvider _cacheProvider;
|
||||
public const string CacheKey = "review_";
|
||||
|
||||
public ReviewController(ILogger<ReviewController> logger, IUnitOfWork unitOfWork, ILicenseService licenseService,
|
||||
IMapper mapper, IReviewService reviewService, IMemoryCache cache, IScrobblingService scrobblingService)
|
||||
IMapper mapper, IReviewService reviewService, IScrobblingService scrobblingService,
|
||||
IEasyCachingProviderFactory cachingProviderFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_unitOfWork = unitOfWork;
|
||||
_licenseService = licenseService;
|
||||
_mapper = mapper;
|
||||
_reviewService = reviewService;
|
||||
_cache = cache;
|
||||
_scrobblingService = scrobblingService;
|
||||
|
||||
_cacheProvider = cachingProviderFactory.GetCachingProvider(EasyCacheProfiles.KavitaPlusReviews);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -63,15 +66,26 @@ public class ReviewController : BaseApiController
|
|||
var cacheKey = CacheKey + seriesId;
|
||||
IEnumerable<UserReviewDto> externalReviews;
|
||||
var setCache = false;
|
||||
if (_cache.TryGetValue(cacheKey, out string cachedData))
|
||||
|
||||
var result = await _cacheProvider.GetAsync<IEnumerable<UserReviewDto>>(cacheKey);
|
||||
if (result.HasValue)
|
||||
{
|
||||
externalReviews = JsonConvert.DeserializeObject<IEnumerable<UserReviewDto>>(cachedData);
|
||||
externalReviews = result.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
externalReviews = await _reviewService.GetReviewsForSeries(userId, seriesId);
|
||||
setCache = true;
|
||||
}
|
||||
// if (_cache.TryGetValue(cacheKey, out string cachedData))
|
||||
// {
|
||||
// externalReviews = JsonConvert.DeserializeObject<IEnumerable<UserReviewDto>>(cachedData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// externalReviews = await _reviewService.GetReviewsForSeries(userId, seriesId);
|
||||
// setCache = true;
|
||||
// }
|
||||
|
||||
// Fetch external reviews and splice them in
|
||||
foreach (var r in externalReviews)
|
||||
|
|
@ -81,10 +95,11 @@ public class ReviewController : BaseApiController
|
|||
|
||||
if (setCache)
|
||||
{
|
||||
var cacheEntryOptions = new MemoryCacheEntryOptions()
|
||||
.SetSize(userRatings.Count)
|
||||
.SetAbsoluteExpiration(TimeSpan.FromHours(10));
|
||||
_cache.Set(cacheKey, JsonConvert.SerializeObject(externalReviews), cacheEntryOptions);
|
||||
// var cacheEntryOptions = new MemoryCacheEntryOptions()
|
||||
// .SetSize(userRatings.Count)
|
||||
// .SetAbsoluteExpiration(TimeSpan.FromHours(10));
|
||||
//_cache.Set(cacheKey, JsonConvert.SerializeObject(externalReviews), cacheEntryOptions);
|
||||
await _cacheProvider.SetAsync(cacheKey, externalReviews, TimeSpan.FromHours(10));
|
||||
_logger.LogDebug("Caching external reviews for {Key}", cacheKey);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue