From 5cdf53b7cee6bc46425546a7026d4661d7e1975d Mon Sep 17 00:00:00 2001 From: lenafx Date: Thu, 4 Dec 2025 15:39:38 +0100 Subject: [PATCH] little improvement on book api --- src/api/books/books.service.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/api/books/books.service.ts b/src/api/books/books.service.ts index 6e18fa9..f3ab98b 100644 --- a/src/api/books/books.service.ts +++ b/src/api/books/books.service.ts @@ -145,8 +145,11 @@ export async function searchBooksInExtension(ext: Extension | null, name: string if (!ext) return []; if ((ext.type === 'book-board') && ext.search) { + const start = performance.now(); + try { console.log(`[${name}] Searching for book: ${query}`); + const matches = await ext.search({ query: query, media: { @@ -156,7 +159,16 @@ export async function searchBooksInExtension(ext: Extension | null, name: string } }); - if (matches && matches.length > 0) { + const end = performance.now(); + console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`); + console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`); + console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`); + console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`); + console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`); + console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`); + console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`); + + if (matches?.length) { return matches.map(m => ({ id: m.id, extensionName: name, @@ -168,6 +180,7 @@ export async function searchBooksInExtension(ext: Extension | null, name: string isExtensionResult: true })); } + } catch (e) { console.error(`Extension search failed for ${name}:`, e); } @@ -269,7 +282,7 @@ async function searchChaptersInExtension(ext: Extension, name: string, searchTit } } -export async function getChaptersForBook(id: string, ext: Boolean): Promise<{ chapters: ChapterWithProvider[] }> { +export async function getChaptersForBook(id: string, ext: Boolean, onlyProvider?: string): Promise<{ chapters: ChapterWithProvider[] }> { let bookData: Book | null = null; let searchTitle: string = ""; @@ -298,6 +311,7 @@ export async function getChaptersForBook(id: string, ext: Boolean): Promise<{ ch if (ext) exts = "ext"; for (const [name, ext] of bookExtensions) { + if (onlyProvider && name !== onlyProvider) continue; if (name == extension) { const chapters = await searchChaptersInExtension(ext, name, id, false, exts); allChapters.push(...chapters); @@ -340,7 +354,7 @@ export async function getChapterContent(bookId: string, chapterIndex: string, pr } const isExternal = source !== 'anilist'; - const chapterList = await getChaptersForBook(bookId, isExternal); + const chapterList = await getChaptersForBook(bookId, isExternal, providerName); if (!chapterList?.chapters || chapterList.chapters.length === 0) { throw new Error("Chapters not found");