From 57a19f87ba5035fb3d8cdd30c956a10b20533e60 Mon Sep 17 00:00:00 2001 From: pax Date: Thu, 9 Apr 2026 20:01:34 -0500 Subject: [PATCH] gelbooru: re-add background prefetch for batch API fast path only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When _batch_api_works is True (Gelbooru proper with auth, persisted from a prior session's probe), search() fires prefetch_batch in the background. The batch tag API covers the entire page's tags in 1-2 requests during the time between grid render and user click — the cache is warm before the info panel opens, so categories appear instantly with no flash of flat tags. Gated on _batch_api_works is True (not None, not False): - Gelbooru proper: prefetches (batch API known good) - Rule34: skips (batch_api_works = False, persisted) - Safebooru.org: skips (no auth → fetcher skips batch capability) Rule34 / Safebooru.org / Moebooru stay on-demand: the ~200ms per-click HTML scrape is unavoidable for those sites because their only path is per-post page fetching, which can't be batched. --- booru_viewer/core/api/gelbooru.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/booru_viewer/core/api/gelbooru.py b/booru_viewer/core/api/gelbooru.py index 23f0d59..96a3510 100644 --- a/booru_viewer/core/api/gelbooru.py +++ b/booru_viewer/core/api/gelbooru.py @@ -81,6 +81,18 @@ class GelbooruClient(BooruClient): created_at=_parse_date(item.get("created_at")), ) ) + # Background prefetch ONLY when the batch tag API is known to + # work (persisted probe result = True, i.e. Gelbooru proper + # with auth). One request covers all tags for the page, so the + # cache is warm before the user clicks. Rule34/Safebooru.org + # skip this (batch_api_works is False or None) — their only + # path is per-post HTML which runs on click. + if ( + self.category_fetcher is not None + and self.category_fetcher._batch_api_works is True + ): + import asyncio + asyncio.create_task(self.category_fetcher.prefetch_batch(posts)) return posts @staticmethod