@@ -9,6 +9,7 @@
|
||||
import type {
|
||||
ApolloClient,
|
||||
DocumentNode,
|
||||
InMemoryCache,
|
||||
MaybeMasked,
|
||||
OperationVariables,
|
||||
TypedDocumentNode,
|
||||
@@ -217,6 +218,7 @@ import {
|
||||
DownloaderState,
|
||||
DownloadUpdateType,
|
||||
FetchSourceMangaType,
|
||||
MangaJobStatus,
|
||||
SortOrder,
|
||||
} from '@/lib/graphql/generated/graphql-base.types.ts';
|
||||
import { GET_GLOBAL_METADATAS } from '@/lib/graphql/metadata/GlobalMetadataQuery.ts';
|
||||
@@ -269,7 +271,12 @@ import {
|
||||
START_DOWNLOADER,
|
||||
STOP_DOWNLOADER,
|
||||
} from '@/lib/graphql/download/DownloaderMutation.ts';
|
||||
import { GET_CHAPTERS_HISTORY, GET_CHAPTERS_MANGA, GET_CHAPTERS_UPDATES } from '@/lib/graphql/chapter/ChapterQuery.ts';
|
||||
import {
|
||||
GET_CHAPTERS_HISTORY,
|
||||
GET_CHAPTERS_MANGA,
|
||||
GET_CHAPTERS_READER,
|
||||
GET_CHAPTERS_UPDATES,
|
||||
} from '@/lib/graphql/chapter/ChapterQuery.ts';
|
||||
import {
|
||||
GET_CHAPTER_PAGES_FETCH,
|
||||
GET_MANGA_CHAPTERS_FETCH,
|
||||
@@ -328,6 +335,7 @@ import { KO_SYNC_LOGIN, KO_SYNC_LOGOUT } from '@/lib/graphql/koreader/KoreaderSy
|
||||
import { GET_KO_SYNC_STATUS } from '@/lib/graphql/koreader/KoreaderSyncQuery.ts';
|
||||
import { ImageCache } from '@/lib/service-worker/ImageCache.ts';
|
||||
import { Sources } from '@/features/source/services/Sources.ts';
|
||||
import uniqBy from 'lodash/fp/uniqBy';
|
||||
|
||||
enum GQLMethod {
|
||||
QUERY = 'QUERY',
|
||||
@@ -2220,7 +2228,7 @@ export class RequestManager {
|
||||
{
|
||||
id: Number(mangaId),
|
||||
},
|
||||
{ refetchQueries: [GET_CHAPTERS_MANGA], errorPolicy: 'all', ...options },
|
||||
{ refetchQueries: [GET_CHAPTERS_MANGA, GET_CHAPTERS_READER], errorPolicy: 'all', ...options },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3327,6 +3335,18 @@ export class RequestManager {
|
||||
options,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
this.graphQLClient.client.refetchQueries({
|
||||
updateCache(cache) {
|
||||
uniqBy('mangaId', result.data?.chapters.nodes).forEach((chapter) => {
|
||||
Object.keys((cache as InMemoryCache).extract().ROOT_QUERY as object)
|
||||
.filter((key) => key.includes('chapters') && key.includes(`mangaId":${chapter.mangaId}`))
|
||||
.forEach((key) => cache.evict({ fieldName: key }));
|
||||
});
|
||||
},
|
||||
});
|
||||
}, [result]);
|
||||
|
||||
return {
|
||||
...result,
|
||||
fetchMore: (...args: Parameters<(typeof result)['fetchMore']>) => {
|
||||
@@ -3515,12 +3535,22 @@ export class RequestManager {
|
||||
onData: (onDataOptions) => {
|
||||
const updatesChanged = onDataOptions.data.data?.libraryUpdateStatusChanged;
|
||||
|
||||
const cache = this.graphQLClient.client.cache as InMemoryCache;
|
||||
|
||||
if (!updatesChanged?.omittedUpdates) {
|
||||
updatesChanged?.mangaUpdates
|
||||
.filter((update) => update.status === MangaJobStatus.Complete)
|
||||
.forEach((update) =>
|
||||
Object.keys(cache.extract().ROOT_QUERY as object)
|
||||
.filter(
|
||||
(key) =>
|
||||
key.includes('chapters') && key.includes(`mangaId":${update.manga.id}`),
|
||||
)
|
||||
.forEach((key) => cache.evict({ fieldName: key })),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const { cache } = this.graphQLClient.client;
|
||||
|
||||
cache.gc();
|
||||
cache.evict({ broadcast: true, id: 'LibraryUpdateStatus' });
|
||||
cache.evict({ broadcast: true, fieldName: 'libraryUpdateStatus' });
|
||||
|
||||
Reference in New Issue
Block a user