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.
This commit is contained in:
parent
a5f33237dd
commit
a9d177ee91
@ -765,18 +765,18 @@ class BooruApp(QMainWindow):
|
|||||||
self._prefetch_adjacent(index)
|
self._prefetch_adjacent(index)
|
||||||
|
|
||||||
def _prefetch_adjacent(self, index: int) -> None:
|
def _prefetch_adjacent(self, index: int) -> None:
|
||||||
"""Silently download the next and previous posts in the background."""
|
"""Silently download adjacent posts with staggered delays."""
|
||||||
for offset in (1, -1, 2):
|
async def _prefetch_batch():
|
||||||
adj = index + offset
|
for i, offset in enumerate((1, -1)):
|
||||||
if 0 <= adj < len(self._posts):
|
adj = index + offset
|
||||||
url = self._posts[adj].file_url
|
if 0 <= adj < len(self._posts) and self._posts[adj].file_url:
|
||||||
if url:
|
if i > 0:
|
||||||
async def _prefetch(u=url):
|
await asyncio.sleep(1)
|
||||||
try:
|
try:
|
||||||
await download_image(u)
|
await download_image(self._posts[adj].file_url)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self._run_async(_prefetch)
|
self._run_async(_prefetch_batch)
|
||||||
|
|
||||||
def _on_download_progress(self, downloaded: int, total: int) -> None:
|
def _on_download_progress(self, downloaded: int, total: int) -> None:
|
||||||
if total > 0:
|
if total > 0:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user