Fixed a missing cache check for publisher images when they fail.
This commit is contained in:
parent
79837d9eca
commit
c1b8c70473
6 changed files with 34 additions and 5 deletions
|
|
@ -8,6 +8,10 @@ public static class EasyCacheProfiles
|
||||||
public const string RevokedJwt = "revokedJWT";
|
public const string RevokedJwt = "revokedJWT";
|
||||||
public const string Favicon = "favicon";
|
public const string Favicon = "favicon";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Images for Publishers
|
||||||
|
/// </summary>
|
||||||
|
public const string Publisher = "publisherImages";
|
||||||
|
/// <summary>
|
||||||
/// If a user's license is valid
|
/// If a user's license is valid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string License = "license";
|
public const string License = "license";
|
||||||
|
|
|
||||||
|
|
@ -397,7 +397,11 @@ public class ChapterController : BaseApiController
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns Ratings and Reviews for an individual Chapter
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="chapterId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpGet("chapter-detail-plus")]
|
[HttpGet("chapter-detail-plus")]
|
||||||
public async Task<ActionResult<ChapterDetailPlusDto>> ChapterDetailPlus([FromQuery] int chapterId)
|
public async Task<ActionResult<ChapterDetailPlusDto>> ChapterDetailPlus([FromQuery] int chapterId)
|
||||||
{
|
{
|
||||||
|
|
@ -425,7 +429,7 @@ public class ChapterController : BaseApiController
|
||||||
|
|
||||||
ret.Ratings = await _unitOfWork.ChapterRepository.GetExternalChapterRatings(chapterId);
|
ret.Ratings = await _unitOfWork.ChapterRepository.GetExternalChapterRatings(chapterId);
|
||||||
|
|
||||||
return ret;
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,11 @@ public class RatingController : BaseApiController
|
||||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-error"));
|
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")]
|
[HttpGet("overall-series")]
|
||||||
public async Task<ActionResult<RatingDto>> GetOverallSeriesRating(int seriesId)
|
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")]
|
[HttpGet("overall-chapter")]
|
||||||
public async Task<ActionResult<RatingDto>> GetOverallChapterRating(int chapterId)
|
public async Task<ActionResult<RatingDto>> GetOverallChapterRating(int chapterId)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -590,14 +590,14 @@ public class UserRepository : IUserRepository
|
||||||
{
|
{
|
||||||
return await _context.AppUserRating
|
return await _context.AppUserRating
|
||||||
.Where(r => r.SeriesId == seriesId && r.AppUserId == userId)
|
.Where(r => r.SeriesId == seriesId && r.AppUserId == userId)
|
||||||
.SingleOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<AppUserChapterRating?> GetUserChapterRatingAsync(int userId, int chapterId)
|
public async Task<AppUserChapterRating?> GetUserChapterRatingAsync(int userId, int chapterId)
|
||||||
{
|
{
|
||||||
return await _context.AppUserChapterRating
|
return await _context.AppUserChapterRating
|
||||||
.Where(r => r.AppUserId == userId && r.ChapterId == chapterId)
|
.Where(r => r.AppUserId == userId && r.ChapterId == chapterId)
|
||||||
.SingleOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IList<UserReviewDto>> GetUserRatingDtosForSeriesAsync(int seriesId, int userId)
|
public async Task<IList<UserReviewDto>> GetUserRatingDtosForSeriesAsync(int seriesId, int userId)
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ public static class ApplicationServiceExtensions
|
||||||
services.AddEasyCaching(options =>
|
services.AddEasyCaching(options =>
|
||||||
{
|
{
|
||||||
options.UseInMemory(EasyCacheProfiles.Favicon);
|
options.UseInMemory(EasyCacheProfiles.Favicon);
|
||||||
|
options.UseInMemory(EasyCacheProfiles.Publisher);
|
||||||
options.UseInMemory(EasyCacheProfiles.Library);
|
options.UseInMemory(EasyCacheProfiles.Library);
|
||||||
options.UseInMemory(EasyCacheProfiles.RevokedJwt);
|
options.UseInMemory(EasyCacheProfiles.RevokedJwt);
|
||||||
options.UseInMemory(EasyCacheProfiles.LocaleOptions);
|
options.UseInMemory(EasyCacheProfiles.LocaleOptions);
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ public class CoverDbService : ICoverDbService
|
||||||
private readonly IImageService _imageService;
|
private readonly IImageService _imageService;
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
private readonly IEventHub _eventHub;
|
private readonly IEventHub _eventHub;
|
||||||
|
private TimeSpan _cacheTime = TimeSpan.FromDays(10);
|
||||||
|
|
||||||
private const string NewHost = "https://www.kavitareader.com/CoversDB/";
|
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");
|
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))
|
if (FaviconUrlMapper.TryGetValue(baseUrl, out var value))
|
||||||
{
|
{
|
||||||
url = value;
|
url = value;
|
||||||
|
|
@ -185,6 +186,15 @@ public class CoverDbService : ICoverDbService
|
||||||
{
|
{
|
||||||
try
|
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);
|
var publisherLink = await FallbackToKavitaReaderPublisher(publisherName);
|
||||||
if (string.IsNullOrEmpty(publisherLink))
|
if (string.IsNullOrEmpty(publisherLink))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue