Prefetch adjacent posts for faster click-to-play

When viewing a post, silently downloads the next, previous, and
second-next posts in the background. Cached files are skipped.
This commit is contained in:
pax 2026-04-05 00:27:07 -05:00
parent ea08e0e3e4
commit a5f33237dd

View File

@ -761,6 +761,23 @@ class BooruApp(QMainWindow):
self._run_async(_load) self._run_async(_load)
# Prefetch adjacent posts
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)
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:
self._dl_progress.setRange(0, total) self._dl_progress.setRange(0, total)