mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
* 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.
62 lines
2.0 KiB
C#
62 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using API.Constants;
|
|
using API.DTOs;
|
|
using API.Services.Plus;
|
|
using EasyCaching.Core;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace API.Controllers;
|
|
|
|
/// <summary>
|
|
/// Responsible for providing external ratings for Series
|
|
/// </summary>
|
|
public class RatingController : BaseApiController
|
|
{
|
|
private readonly ILicenseService _licenseService;
|
|
private readonly IRatingService _ratingService;
|
|
private readonly ILogger<RatingController> _logger;
|
|
private readonly IEasyCachingProvider _cacheProvider;
|
|
public const string CacheKey = "rating_";
|
|
|
|
public RatingController(ILicenseService licenseService, IRatingService ratingService,
|
|
ILogger<RatingController> logger, IEasyCachingProviderFactory cachingProviderFactory)
|
|
{
|
|
_licenseService = licenseService;
|
|
_ratingService = ratingService;
|
|
_logger = logger;
|
|
|
|
_cacheProvider = cachingProviderFactory.GetCachingProvider(EasyCacheProfiles.KavitaPlusRatings);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the external ratings for a given series
|
|
/// </summary>
|
|
/// <param name="seriesId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Recommendation, VaryByQueryKeys = new []{"seriesId"})]
|
|
public async Task<ActionResult<IEnumerable<RatingDto>>> GetRating(int seriesId)
|
|
{
|
|
if (!await _licenseService.HasActiveLicense())
|
|
{
|
|
return Ok(new List<RatingDto>());
|
|
}
|
|
|
|
var cacheKey = CacheKey + seriesId;
|
|
var results = await _cacheProvider.GetAsync<IEnumerable<RatingDto>>(cacheKey);
|
|
if (results.HasValue)
|
|
{
|
|
return Ok(results.Value);
|
|
}
|
|
|
|
var ratings = await _ratingService.GetRatings(seriesId);
|
|
await _cacheProvider.SetAsync(cacheKey, ratings, TimeSpan.FromHours(24));
|
|
_logger.LogDebug("Caching external rating for {Key}", cacheKey);
|
|
return Ok(ratings);
|
|
|
|
}
|
|
}
|