mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-13 09:19:56 -05:00
Fix: Optimizations for Reader
This commit is contained in:
@@ -31,15 +31,13 @@ In-Progress:
|
|||||||
- Enable Cloudflare Bypass (Suwayomi Config) (Requires Patching)
|
- Enable Cloudflare Bypass (Suwayomi Config) (Requires Patching)
|
||||||
|
|
||||||
- Working on 3D Display Cards
|
- Working on 3D Display Cards
|
||||||
- Chapter refresh Notification Looks bad (Series Detail)
|
|
||||||
|
|
||||||
- Fix Discover Workout
|
|
||||||
- Fix CSS on Saved State for Search
|
|
||||||
|
|
||||||
- Add Small QOL Animations where Appropriate
|
- Add Small QOL Animations where Appropriate
|
||||||
|
|
||||||
- Add Flathub Support (Pending Video)
|
- Add Flathub Support (Pending Video)
|
||||||
|
|
||||||
|
- Working on Optimizing Reader (CURRENT)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Testing:
|
Testing:
|
||||||
@@ -35,15 +35,19 @@
|
|||||||
purple: "#a07ac4",
|
purple: "#a07ac4",
|
||||||
};
|
};
|
||||||
|
|
||||||
const pageCache = new Map<number, string[]>();
|
const pageCache = new Map<number, string[]>();
|
||||||
const inflight = new Map<number, Promise<string[]>>();
|
const inflight = new Map<number, Promise<string[]>>();
|
||||||
|
const resolvedUrlCache = new Map<string, Promise<string>>();
|
||||||
|
const preloadedUrls = new Set<string>();
|
||||||
|
|
||||||
const win = getCurrentWindow();
|
const win = getCurrentWindow();
|
||||||
|
|
||||||
const useBlob = $derived((appStore.settings.serverAuthMode ?? "NONE") === "BASIC_AUTH");
|
const useBlob = $derived((appStore.settings.serverAuthMode ?? "NONE") === "BASIC_AUTH");
|
||||||
|
|
||||||
function resolveUrl(url: string, priority = 0): Promise<string> {
|
function resolveUrl(url: string, priority = 0): Promise<string> {
|
||||||
return useBlob ? getBlobUrl(url, priority) : Promise.resolve(url);
|
if (!useBlob) return Promise.resolve(url);
|
||||||
|
if (!resolvedUrlCache.has(url)) resolvedUrlCache.set(url, getBlobUrl(url, priority));
|
||||||
|
return resolvedUrlCache.get(url)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchPages(chapterId: number, signal?: AbortSignal, priorityPage = 0): Promise<string[]> {
|
function fetchPages(chapterId: number, signal?: AbortSignal, priorityPage = 0): Promise<string[]> {
|
||||||
@@ -87,6 +91,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function preloadImage(url: string) {
|
function preloadImage(url: string) {
|
||||||
|
if (preloadedUrls.has(url)) return;
|
||||||
|
preloadedUrls.add(url);
|
||||||
resolveUrl(url).then(src => { new Image().src = src; }).catch(() => {});
|
resolveUrl(url).then(src => { new Image().src = src; }).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,7 +405,7 @@
|
|||||||
if (!next || stripChapters.some(c => c.chapterId === next.id)) return;
|
if (!next || stripChapters.some(c => c.chapterId === next.id)) return;
|
||||||
appending = true;
|
appending = true;
|
||||||
fetchPages(next.id)
|
fetchPages(next.id)
|
||||||
.then(urls => { urls.forEach(url => measureAspect(url).catch(() => {})); urls.slice(0, 6).forEach(preloadImage); return urls; })
|
.then(urls => { urls.slice(0, 6).forEach(preloadImage); return urls; })
|
||||||
.then(urls => {
|
.then(urls => {
|
||||||
if (stripChapters.some(c => c.chapterId === next.id)) { appending = false; return; }
|
if (stripChapters.some(c => c.chapterId === next.id)) { appending = false; return; }
|
||||||
stripChapters = [...stripChapters, { chapterId: next.id, chapterName: next.name, urls }];
|
stripChapters = [...stripChapters, { chapterId: next.id, chapterName: next.name, urls }];
|
||||||
@@ -469,14 +475,9 @@
|
|||||||
if (store.activeChapter && store.activeChapterList.length) {
|
if (store.activeChapter && store.activeChapterList.length) {
|
||||||
const idx = store.activeChapterList.findIndex(c => c.id === store.activeChapter!.id);
|
const idx = store.activeChapterList.findIndex(c => c.id === store.activeChapter!.id);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
for (let i = 1; i <= 3; i++) {
|
const next = store.activeChapterList[idx + 1];
|
||||||
const entry = store.activeChapterList[idx + i];
|
if (next) fetchPages(next.id).then(urls => urls.slice(0, 8).forEach(preloadImage)).catch(() => {});
|
||||||
if (!entry) break;
|
if (idx > 0) fetchPages(store.activeChapterList[idx - 1].id).then(urls => urls.slice(0, 2).forEach(preloadImage)).catch(() => {});
|
||||||
fetchPages(entry.id)
|
|
||||||
.then(urls => { const n = i === 1 ? 8 : i === 2 ? 4 : 2; urls.slice(0, n).forEach(preloadImage); })
|
|
||||||
.catch(() => {});
|
|
||||||
}
|
|
||||||
if (idx > 0) fetchPages(store.activeChapterList[idx - 1].id).catch(() => {});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user