From a9d177ee91d624c99a308eaf31ce488441c18eec Mon Sep 17 00:00:00 2001 From: pax Date: Sun, 5 Apr 2026 00:28:35 -0500 Subject: [PATCH] Throttle prefetch: only next+prev, 1s stagger, sequential Reduced from 3 concurrent prefetches to 2 sequential with 1s delay between them. Avoids hitting Danbooru's 10 req/s rate limit. --- booru_viewer/gui/app.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/booru_viewer/gui/app.py b/booru_viewer/gui/app.py index c4d676f..81b4930 100644 --- a/booru_viewer/gui/app.py +++ b/booru_viewer/gui/app.py @@ -765,18 +765,18 @@ class BooruApp(QMainWindow): self._prefetch_adjacent(index) def _prefetch_adjacent(self, index: int) -> None: - """Silently download the next and previous posts in the background.""" - for offset in (1, -1, 2): - adj = index + offset - if 0 <= adj < len(self._posts): - url = self._posts[adj].file_url - if url: - async def _prefetch(u=url): - try: - await download_image(u) - except Exception: - pass - self._run_async(_prefetch) + """Silently download adjacent posts with staggered delays.""" + async def _prefetch_batch(): + for i, offset in enumerate((1, -1)): + adj = index + offset + if 0 <= adj < len(self._posts) and self._posts[adj].file_url: + if i > 0: + await asyncio.sleep(1) + try: + await download_image(self._posts[adj].file_url) + except Exception: + pass + self._run_async(_prefetch_batch) def _on_download_progress(self, downloaded: int, total: int) -> None: if total > 0: