From 35424ff89d114e0b6d2eb0d5d65a07b0add28a25 Mon Sep 17 00:00:00 2001 From: pax Date: Thu, 9 Apr 2026 19:48:04 -0500 Subject: [PATCH] gelbooru+moebooru: drop background prefetch from search, fetch on demand MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes the asyncio.create_task(prefetch_batch) calls from search() and get_post() in both clients. Tags are now fetched ONLY when the user actually clicks a post (via ensure_categories in the info panel path) or saves with a category-token template. The background prefetch was the source of most of the complexity: probe timing, early-exit bugs from partial composes racing with on-click ensures, Rule34's slow probe blocking the prefetch window. All gone. New flow: search() → fast, returns posts with flat tags only click → ensure_categories fires, ~200ms HTML scrape or batch API, categories arrive, signal re-renders re-click → instant (cache compose, no HTTP) save → ensure in save_post_file, same path The ~200ms per first-click is invisible during the image load. The cache compounds across posts and sessions. The prefetch_batch method stays in CategoryFetcher for potential future use but nothing calls it from the hot path anymore. --- booru_viewer/core/api/gelbooru.py | 3 --- booru_viewer/core/api/moebooru.py | 3 --- 2 files changed, 6 deletions(-) diff --git a/booru_viewer/core/api/gelbooru.py b/booru_viewer/core/api/gelbooru.py index 3544c0f..23f0d59 100644 --- a/booru_viewer/core/api/gelbooru.py +++ b/booru_viewer/core/api/gelbooru.py @@ -81,9 +81,6 @@ class GelbooruClient(BooruClient): created_at=_parse_date(item.get("created_at")), ) ) - if self.category_fetcher is not None: - import asyncio - asyncio.create_task(self.category_fetcher.prefetch_batch(posts)) return posts @staticmethod diff --git a/booru_viewer/core/api/moebooru.py b/booru_viewer/core/api/moebooru.py index e7a404c..8e9c11b 100644 --- a/booru_viewer/core/api/moebooru.py +++ b/booru_viewer/core/api/moebooru.py @@ -56,9 +56,6 @@ class MoebooruClient(BooruClient): created_at=_parse_date(item.get("created_at")), ) ) - if self.category_fetcher is not None: - import asyncio - asyncio.create_task(self.category_fetcher.prefetch_batch(posts)) return posts async def get_post(self, post_id: int) -> Post | None: