Fixed a missing cache check for publisher images when they fail.

This commit is contained in:
Joseph Milazzo 2025-04-29 11:18:22 -05:00
parent 79837d9eca
commit c1b8c70473
6 changed files with 34 additions and 5 deletions

View file

@ -8,6 +8,10 @@ public static class EasyCacheProfiles
public const string RevokedJwt = "revokedJWT";
public const string Favicon = "favicon";
/// <summary>
/// Images for Publishers
/// </summary>
public const string Publisher = "publisherImages";
/// <summary>
/// If a user's license is valid
/// </summary>
public const string License = "license";

View file

@ -397,7 +397,11 @@ public class ChapterController : BaseApiController
return Ok();
}
/// <summary>
/// Returns Ratings and Reviews for an individual Chapter
/// </summary>
/// <param name="chapterId"></param>
/// <returns></returns>
[HttpGet("chapter-detail-plus")]
public async Task<ActionResult<ChapterDetailPlusDto>> ChapterDetailPlus([FromQuery] int chapterId)
{
@ -425,7 +429,7 @@ public class ChapterController : BaseApiController
ret.Ratings = await _unitOfWork.ChapterRepository.GetExternalChapterRatings(chapterId);
return ret;
return Ok(ret);
}
}

View file

@ -68,6 +68,11 @@ public class RatingController : BaseApiController
return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-error"));
}
/// <summary>
/// Overall rating from all Kavita users for a given Series
/// </summary>
/// <param name="seriesId"></param>
/// <returns></returns>
[HttpGet("overall-series")]
public async Task<ActionResult<RatingDto>> GetOverallSeriesRating(int seriesId)
{
@ -79,6 +84,11 @@ public class RatingController : BaseApiController
});
}
/// <summary>
/// Overall rating from all Kavita users for a given Chapter
/// </summary>
/// <param name="chapterId"></param>
/// <returns></returns>
[HttpGet("overall-chapter")]
public async Task<ActionResult<RatingDto>> GetOverallChapterRating(int chapterId)
{

View file

@ -590,14 +590,14 @@ public class UserRepository : IUserRepository
{
return await _context.AppUserRating
.Where(r => r.SeriesId == seriesId && r.AppUserId == userId)
.SingleOrDefaultAsync();
.FirstOrDefaultAsync();
}
public async Task<AppUserChapterRating?> GetUserChapterRatingAsync(int userId, int chapterId)
{
return await _context.AppUserChapterRating
.Where(r => r.AppUserId == userId && r.ChapterId == chapterId)
.SingleOrDefaultAsync();
.FirstOrDefaultAsync();
}
public async Task<IList<UserReviewDto>> GetUserRatingDtosForSeriesAsync(int seriesId, int userId)

View file

@ -85,6 +85,7 @@ public static class ApplicationServiceExtensions
services.AddEasyCaching(options =>
{
options.UseInMemory(EasyCacheProfiles.Favicon);
options.UseInMemory(EasyCacheProfiles.Publisher);
options.UseInMemory(EasyCacheProfiles.Library);
options.UseInMemory(EasyCacheProfiles.RevokedJwt);
options.UseInMemory(EasyCacheProfiles.LocaleOptions);

View file

@ -45,6 +45,7 @@ public class CoverDbService : ICoverDbService
private readonly IImageService _imageService;
private readonly IUnitOfWork _unitOfWork;
private readonly IEventHub _eventHub;
private TimeSpan _cacheTime = TimeSpan.FromDays(10);
private const string NewHost = "https://www.kavitareader.com/CoversDB/";
@ -97,7 +98,7 @@ public class CoverDbService : ICoverDbService
throw new KavitaException($"Kavita has already tried to fetch from {sanitizedBaseUrl} and failed. Skipping duplicate check");
}
await provider.SetAsync(baseUrl, string.Empty, TimeSpan.FromDays(10));
await provider.SetAsync(baseUrl, string.Empty, _cacheTime);
if (FaviconUrlMapper.TryGetValue(baseUrl, out var value))
{
url = value;
@ -185,6 +186,15 @@ public class CoverDbService : ICoverDbService
{
try
{
var provider = _cacheFactory.GetCachingProvider(EasyCacheProfiles.Publisher);
var res = await provider.GetAsync<string>(publisherName);
if (res.HasValue)
{
_logger.LogInformation("Kavita has already tried to fetch Publisher: {PublisherName} and failed. Skipping duplicate check", publisherName);
throw new KavitaException($"Kavita has already tried to fetch Publisher: {publisherName} and failed. Skipping duplicate check");
}
await provider.SetAsync(publisherName, string.Empty, _cacheTime);
var publisherLink = await FallbackToKavitaReaderPublisher(publisherName);
if (string.IsNullOrEmpty(publisherLink))
{