Cache first page of source manga fetch response (#666)

This commit is contained in:
schroda
2024-03-23 23:34:20 +01:00
committed by GitHub
parent 452ac4fd9a
commit 83635faf95

View File

@@ -449,6 +449,15 @@ export class RequestManager {
return;
}
const isFirstPage = pageToRevalidate === 1;
const isTtlReached =
Date.now() - (this.cache.getFetchTimestampFor(cacheResultsKey, getVariablesFor(pageToRevalidate)) ?? 0) >=
1000 * 60 * 5;
if (isFirstPage && !isTtlReached) {
return;
}
const { response: revalidationRequest } = this.doRequest(
GQLMethod.MUTATION,
GET_SOURCE_MANGAS_FETCH,
@@ -463,11 +472,9 @@ export class RequestManager {
const cachedPageData = this.cache.getResponseFor<
AbortableApolloUseMutationPaginatedResponse<Data, Variables>[1][number]
>(cacheResultsKey, getVariablesFor(pageToRevalidate));
const isCachedPageInvalid = checkIfCachedPageIsInvalid(cachedPageData, revalidationResponse);
if (isCachedPageInvalid) {
this.cache.cacheResponse(cacheResultsKey, getVariablesFor(pageToRevalidate), revalidationResponse);
}
this.cache.cacheResponse(cacheResultsKey, getVariablesFor(pageToRevalidate), revalidationResponse);
if (!hasNextPage(revalidationResponse)) {
const currentCachedPages = this.cache.getResponseFor<Set<number>>(cachePagesKey, getVariablesFor(0))!;