Prefetch in all 8 directions (ring expansion) not just linear
Expands outward in a grid-aware ring: left, right, up, down, and all 4 diagonals at each distance level. Covers the page more evenly.
This commit is contained in:
parent
2156dec91d
commit
e91d7d8a51
@ -809,17 +809,31 @@ 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:
|
||||||
"""Prefetch outward from clicked post, gradually covering the whole page."""
|
"""Prefetch outward from clicked post in all directions, covering the whole page."""
|
||||||
total = len(self._posts)
|
total = len(self._posts)
|
||||||
if total == 0:
|
if total == 0:
|
||||||
return
|
return
|
||||||
|
cols = self._grid._flow.columns
|
||||||
|
|
||||||
# Build spiral order: distance 1, 2, 3... from index
|
# Build ring order: at each distance, grab all 8 directions
|
||||||
|
seen = {index}
|
||||||
order = []
|
order = []
|
||||||
for dist in range(1, total):
|
for dist in range(1, total):
|
||||||
|
ring = set()
|
||||||
|
for dy in (-dist, 0, dist):
|
||||||
|
for dx in (-dist, 0, dist):
|
||||||
|
if dy == 0 and dx == 0:
|
||||||
|
continue
|
||||||
|
adj = index + dy * cols + dx
|
||||||
|
if 0 <= adj < total and adj not in seen:
|
||||||
|
ring.add(adj)
|
||||||
|
# Also add pure linear neighbors for non-grid nav
|
||||||
for adj in (index + dist, index - dist):
|
for adj in (index + dist, index - dist):
|
||||||
if 0 <= adj < total:
|
if 0 <= adj < total and adj not in seen:
|
||||||
order.append(adj)
|
ring.add(adj)
|
||||||
|
for adj in sorted(ring):
|
||||||
|
seen.add(adj)
|
||||||
|
order.append(adj)
|
||||||
if len(order) >= total - 1:
|
if len(order) >= total - 1:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user