Skip to content

Commit 83e6c4e

Browse files
committed
feat: removed cache
1 parent c84a2e1 commit 83e6c4e

File tree

4 files changed

+11
-75
lines changed

4 files changed

+11
-75
lines changed

src/generic/main.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ import { Forms } from "./forms";
2424
import type { MangaMetadata, WindowEntry } from "./models";
2525
import { MainInterceptor, Requests } from "./network";
2626
import { Parsers } from "./parsers";
27-
import { Cache, FilterPreferences, JsonParser, Tags, Type } from "./utils";
27+
import { FilterPreferences, JsonParser, Tags, Type } from "./utils";
2828

29-
export const cache = new Cache();
3029
export const filter = new FilterPreferences();
3130
export const tags = new Tags();
3231
export const types = new Type();
@@ -165,10 +164,8 @@ export abstract class MangaWorldGeneric
165164
}
166165

167166
async getMangaDetails(mangaId: string): Promise<SourceManga> {
168-
const data = cache.getPageCache(
169-
mangaId,
167+
const data = this.requestManager.fetchPage(
170168
`${this.base_url}/manga/${mangaId}`,
171-
this,
172169
);
173170
const html = Application.arrayBufferToUTF8String(await data);
174171
const windowEntry = jsonParser.getWindowEntry(html);
@@ -181,22 +178,17 @@ export abstract class MangaWorldGeneric
181178
}
182179

183180
async getChapters(sourceManga: SourceManga): Promise<Chapter[]> {
184-
const data = cache.getPageCache(
185-
sourceManga.mangaId,
181+
const data = this.requestManager.fetchPage(
186182
`${this.base_url}/manga/${sourceManga.mangaId}`,
187-
this,
188-
15,
189183
);
190184
const html = Application.arrayBufferToUTF8String(await data);
191185
const windowEntry = jsonParser.getWindowEntry(html);
192186
return this.parser.parseChapters(windowEntry, sourceManga);
193187
}
194188

195189
async getChapterDetails(chapter: Chapter): Promise<ChapterDetails> {
196-
const data = cache.getPageCache(
197-
chapter.sourceManga.mangaId,
190+
const data = this.requestManager.fetchPage(
198191
`${this.base_url}/manga/${chapter.sourceManga.mangaId}`,
199-
this,
200192
);
201193
const html = Application.arrayBufferToUTF8String(await data);
202194
const windowEntry = jsonParser.getWindowEntry(html);
@@ -351,7 +343,7 @@ export abstract class MangaWorldGeneric
351343
metadata: MangaMetadata,
352344
): Promise<PagedResults<DiscoverSectionItem>> {
353345
const html = Application.arrayBufferToUTF8String(
354-
await cache.getPageCache("home", this.base_url, this),
346+
await this.requestManager.fetchPage(this.base_url),
355347
);
356348
const windowEntry = jsonParser.getWindowEntry(html);
357349
return await this.getSection(section.id, windowEntry, metadata);

src/generic/network.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
type SearchQuery,
77
type SortingOption,
88
} from "@paperback/types";
9-
import { cache, filter, MangaWorldGeneric } from "./main";
9+
import { filter, MangaWorldGeneric } from "./main";
1010

1111
export class Requests {
1212
constructSearchRequestURL(
@@ -70,11 +70,7 @@ export class Requests {
7070

7171
async parseFilters(source: MangaWorldGeneric) {
7272
return Application.arrayBufferToUTF8String(
73-
await cache.getPageCache(
74-
"Filter",
75-
`${source.base_url}/archive`,
76-
source,
77-
),
73+
await source.requestManager.fetchPage(`${source.base_url}/archive`),
7874
);
7975
}
8076

@@ -97,10 +93,8 @@ export class Requests {
9793
html = Application.arrayBufferToUTF8String(data);
9894
} else {
9995
html = Application.arrayBufferToUTF8String(
100-
await cache.getPageCache(
101-
`LastMangaAddedTagsSection-${tags}`,
96+
await source.requestManager.fetchPage(
10297
`${source.base_url}/archive?sort=newest&page=${page}&genre=${tags}`,
103-
source,
10498
),
10599
);
106100
}
@@ -119,10 +113,8 @@ export class Requests {
119113
html = Application.arrayBufferToUTF8String(data);
120114
} else {
121115
html = Application.arrayBufferToUTF8String(
122-
await cache.getPageCache(
123-
"PopularSection",
116+
await source.requestManager.fetchPage(
124117
`${source.base_url}/archive?sort=most_read&page=${page}`,
125-
source,
126118
),
127119
);
128120
}

src/generic/parsers.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ import {
99
type SourceManga,
1010
type TagSection,
1111
} from "@paperback/types";
12-
import {
13-
cache,
14-
filter,
15-
jsonParser,
16-
MangaWorldGeneric,
17-
tags,
18-
types,
19-
} from "./main";
12+
import { filter, jsonParser, MangaWorldGeneric, tags, types } from "./main";
2013
import type {
2114
Manga,
2215
MangaChapterList,
@@ -432,7 +425,7 @@ export class Parsers {
432425
const updates: ChapterUpdatesCarouselItem[] = [];
433426
if (page == 1) {
434427
html = Application.arrayBufferToUTF8String(
435-
await cache.getPageCache("home", source.base_url, source),
428+
await source.requestManager.fetchPage(source.base_url),
436429
);
437430
} else {
438431
const data = (

src/generic/utils.ts

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ContentRating, type Tag } from "@paperback/types";
22
import * as cheerio from "cheerio";
33
import { jsonParser, MangaWorldGeneric } from "./main";
44
import type {
5-
CacheItem,
65
ChapterList,
76
Genre,
87
GlobalData,
@@ -18,46 +17,6 @@ import type {
1817
WindowEntry,
1918
} from "./models";
2019

21-
const cacheMap = new Map<string, CacheItem>();
22-
const requestMap = new Map<string, Promise<ArrayBuffer>>();
23-
24-
export class Cache {
25-
async getPageCache(
26-
name: string,
27-
url: string,
28-
source: MangaWorldGeneric,
29-
cacheTime: number = 10,
30-
): Promise<ArrayBuffer> {
31-
const cached = cacheMap.get(name);
32-
if (cached && cached.expires > Math.floor(Date.now() / 1000)) {
33-
return cached.data;
34-
}
35-
36-
// If a request is already in progress for this name, return that promise
37-
if (requestMap.has(name)) {
38-
return requestMap.get(name)!;
39-
}
40-
41-
const fetchPromise = source.requestManager
42-
.fetchPage(url)
43-
.then((data) => {
44-
cacheMap.set(name, {
45-
expires: Math.floor(Date.now() / 1000) + cacheTime,
46-
data: data,
47-
});
48-
requestMap.delete(name);
49-
return data;
50-
})
51-
.catch((error) => {
52-
requestMap.delete(name);
53-
throw error;
54-
});
55-
56-
requestMap.set(name, fetchPromise);
57-
return fetchPromise;
58-
}
59-
}
60-
6120
export class Tags {
6221
/**
6322
* Check Excluded tags

0 commit comments

Comments
 (0)