From 84f879934e4a13db7610c84f207dc0acf004c2df Mon Sep 17 00:00:00 2001 From: Jorrin Date: Thu, 26 Dec 2024 21:08:46 +0100 Subject: [PATCH 1/2] truncate search --- src/api/backend/search/search.ts | 10 ++++++++-- src/routes/index.tsx | 33 ++++++++++++-------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/api/backend/search/search.ts b/src/api/backend/search/search.ts index 66ab548..246c91f 100644 --- a/src/api/backend/search/search.ts +++ b/src/api/backend/search/search.ts @@ -3,6 +3,7 @@ import { BaseRequest, client } from "../base"; import { BookItem } from "../types"; import { SearchParams } from "./types"; import { getExternalDownloads } from "../downloads/external"; +import { ExternalDownloadResponse } from "../downloads/types"; export const getBooks = (params: SearchParams) => { return client>("/books", { @@ -22,10 +23,15 @@ export const useGetBooksQueryWithExternalDownloads = (params: SearchParams) => { queryKey: ["search", params], queryFn: async () => { const books = await getBooks(params); - const externalDownloads = await getExternalDownloads(books.results.map((book) => book.md5)); + const externalDownloads: ExternalDownloadResponse = []; + for (let i = 0; i < params.limit; i += 10) { + const batch = books.results.slice(i, i + 3).map((book) => book.md5); + const batchExternalDownloads = await getExternalDownloads(batch); + externalDownloads.push(...batchExternalDownloads); + } return { ...books, - results: books.results.map((book) => ({ + results: books.results.slice(0, params.limit).map((book) => ({ ...book, externalDownloads: externalDownloads.find((b) => b.md5 === book.md5)?.external_downloads, ipfs: externalDownloads.find((b) => b.md5 === book.md5)?.ipfs, diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 61ce528..4730d80 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -29,7 +29,6 @@ export const Route = createFileRoute("/")({ function Index() { const navigate = useNavigate({ from: Route.fullPath }); const { q } = Route.useSearch(); - const sidebar = useLayoutStore((state) => state.sidebar); const [filters, setFilters] = useState({ view: "list", @@ -64,26 +63,18 @@ function Index() {
-
-
- } - placeholder="Search for books, comics, or manga..." - value={q} - onChange={(e) => - navigate({ - search: { - q: e.target.value, - }, - }) - } - /> -
-
+ } + placeholder="Search for books, comics, or manga..." + value={q} + onChange={(e) => + navigate({ + search: { + q: e.target.value, + }, + }) + } + />
{isLoading && ( From 49f57c6234d6ce87ebe8cf8a5a6e0a0aa3c8d4e7 Mon Sep 17 00:00:00 2001 From: Jorrin Date: Thu, 26 Dec 2024 21:10:10 +0100 Subject: [PATCH 2/2] lint --- src/routes/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 4730d80..e2c6065 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -3,8 +3,6 @@ import { SkeletonBookItem } from "@/components/books/book-item"; import { useDebounce } from "@/hooks/use-debounce"; import { useSettingsStore } from "@/stores/settings"; import { createFileRoute, useNavigate } from "@tanstack/react-router"; -import { useLayoutStore } from "@/stores/layout"; -import { cn } from "@/lib/utils"; import { NavLink } from "@/components/ui/nav-link"; import { Input } from "@/components/ui/input"; import { SearchIcon } from "lucide-react";