Skip to content

Commit

Permalink
Cache first page of source manga fetch response (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroda authored Mar 23, 2024
1 parent 452ac4f commit 83635fa
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/lib/requests/RequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))!;
Expand Down

0 comments on commit 83635fa

Please sign in to comment.